6 条题解

  • 1
    @ 2025-2-23 21:39:40
    #include<bits/stdc++.h>
    using namespace std;
    int a[10001];
    int l,m,x,s,y;
    int main()
    {
    	cin>>l>>m;
    	for(int i=0;i<=l;++i)a[i]=1;
    	for(int i=1;i<=m;++i){
    		cin>>x>>y;
    		for(int j=x;j<=y;++j)
    			a[j]=0;
    	}
    	for(int i=0;i<=l;++i)
    		if(a[i])++s;
    	cout<<s;
    }
    
    
    
    • 0
      @ 2025-3-31 15:22:45

      import java.util.Scanner; public class Main2 {

      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
      
          //输入l的长度,和数组表示这一条路,  且0是有树,1是没树
          int l = sc.nextInt();
          int []arr = new int[l + 1];
      
          //输入区域的数量n
          int n = sc.nextInt();
      
          //输入每个区域的起始位置和长度
          int[][] regionsArr = new int[n][2];
      
          // 输入每个区域的起始位置和长度
          for (int i = 0; i < n; i++) {
              regionsArr[i][0] = sc.nextInt();
              regionsArr[i][1] = sc.nextInt();
          }
      
      
      
          //for循环遍历每个区域
              //开始遍历regionsArr数组
              for (int i = 0; i < regionsArr.length; i++) {
                  //定义地铁区域的起始与结束位置
                  int begin = regionsArr[i][0];
                  int end = regionsArr[i][1];
      
                  //开始遍历数组arr,将里面的树去掉
                  for (int j = begin; j <= end; j++) {
                      arr[j]++;
                  }
              }
      
              //定义count计数剩余的树的数量
              int count = 0;
              for (int i = 0; i < arr.length; i++) {
                  if (arr[i] == 0) {
                      count++;
                  }
              }
      
              //输出count
              System.out.println(count);
      }
      

      }

      • 0
        @ 2025-3-26 3:21:07

        差分

        #include <iostream>
        using namespace std;
        
        const int N = 1e4 + 10;
        int a[N], b[N];
        
        void insert(int l, int r, int c)
        {
            b[l] += c;
            if (r + 1 < N) b[r + 1] -= c;
        }
        
        int main()
        {
            ios::sync_with_stdio(false);
            int n, m, sum = 0;
            cin >> n >> m;
            for (int i = 0; i <= n; i ++ ) a[i] = 1;
            for (int i = 0; i <= n; i ++ ) insert(i, i, a[i]);
            while (m -- ) 
            {
                int l, r;
                cin >> l >> r;
                insert(l, r, -1);
            }
            for (int i = 0; i <= n; i ++ )
            {
                b[i] += b[i - 1];
                if (b[i] > 0) ++ sum ;
            }
            cout << sum;
            cout << endl;
            return 0;
        }
        
        
        • 0
          @ 2025-3-22 13:35:26
          ``#include<bits/stdc++.h>
          using namespace std;
          int a[10000]={0},l,m,u,v,cnt=0;
          int main(){
              cin>>l>>m;
              for(int i=0;i<m;i++){
              	cin>>u>>v;
              	for(int j=u;j<=v;j++){
              		a[j]=1;
          		}
          	}
          	for(int i=0;i<=l;i++){
              	if(a[i]==0){
              		cnt++;
          		}
          	}
              cout<<cnt;
              return 0;
          }
          

          ``

          • 0
            #include<stdio.h>
            int main()
            {
              int l,m;
              int a[100001];
              scanf("%d %d",&l,&m);
              for(int i=0;i<=l;i++){
                a[i]=1;
              }
              int u,v;
              for(int i=1;i<=m;i++){
                scanf("%d %d",&u,&v);
                for(int j=u;j<=v;j++){
                  a[j]=0;
                }
              }
              int sum=0;
              for(int i=0;i<=l;i++){
                if(a[i]==1){
                  sum++;
                }
              }
              printf("%d",sum);
              return 0;
            }
            
            • 0
              @ 2024-11-10 9:52:24

              Water!模拟即可。

              #include<bits/stdc++.h>
              using namespace std;
              int a[10001];
              int l,m,x,s,y;
              int main()
              {
              	cin>>l>>m;
              	for(int i=0;i<=l;++i)a[i]=1;
              	for(int i=1;i<=m;++i){
              		cin>>x>>y;
              		for(int j=x;j<=y;++j)
              			a[j]=0;
              	}
              	for(int i=0;i<=l;++i)
              		if(a[i])++s;
              	cout<<s;
              }
              
              • 1

              信息

              ID
              5105
              时间
              1000ms
              内存
              125MiB
              难度
              1
              标签
              递交数
              434
              已通过
              232
              上传者