2 solutions

  • 0
    @ 2024-10-6 11:31:32

    #include<stdio.h> int main(){ int i,j,x,y,L,M,num[10001]; int cnt=0; scanf("%d %d",&L,&M); for(i=0;i<=L;i++){ num[i]=1; } for(i=1;i<=M;i++){ scanf("%d %d",&x,&y); for(j=x;j<=y;j++){ num[j]=0; } } for(i=0;i<=L;i++){ if(num[i]==1)cnt++; } printf("%d",cnt); return 0; }

    • 0
      @ 2024-3-19 11:10:08
      #include<stdio.h>
      int main(){
          int l,m;
          scanf("%d %d",&l,&m);
          int a[l+1];
          int i;
          for(i=0;i<=l;i++){  //初始化树位置,0代表不需移走该下标的树
              a[i]=0;  
          }
          int s,e;
          for(i=0;i<m;i++){
              scanf("%d %d",&s,&e);
              for(int j=s;j<=e;j++){//标记需移走树的位置
                  a[j]++;
              }
          }
          int sum=0;
          for(i=0;i<=l;i++){
              if(a[i]==0){  //查找未被标记的树个数
                  sum++;
              }
          }
          printf("%d",sum);
          return 0;
      }
      
      • 1

      Information

      ID
      6771
      Time
      1000ms
      Memory
      128MiB
      Difficulty
      6
      Tags
      (None)
      # Submissions
      206
      Accepted
      57
      Uploaded By