几乎一样的思路为什么过不了啊

P1047 [NOIP2005 普及组] 校门外的树

y1219323890 @ 2024-01-14 23:07:03

应该是超时了但是为什么上面的超时了下面的没有抄啊```

include<iostream>

using namespace std; int main(){ int tree[10001];int l,m; int u,v;int cnt; cin>>l>>m; for(int i=0;i<=l;i++)tree[i]=0; for(int i=1;i<=m;i++){ cin>>u>>v; for(int i=u;i<=v;i++) if(tree[i]==0){ tree[i]++;
} } for(int i=0;i<=l;i++) if(tree[i]==0) cnt++; cout<<cnt; return 0; } //***

include <iostream>

using namespace std; int main(){ int i,j,k,m,n,l,sum=0; int a[10001],q,z; cin>>l>>m; for(i=0;i<=l;i++)a[i]=0; for(i=1;i<=m;i++) { cin>>q>>z;
for(j=q;j<=z;j++)if(a[j]==0)a[j]++; } for(i=0;i<=l;i++)if(a[i]==0)sum++; cout<<sum; }


by y1219323890 @ 2024-01-14 23:09:39

#include<iostream>
using namespace std;
int main(){
    int tree[10001];int l,m;
    int u,v;int cnt;
    cin>>l>>m;
      for(int i=0;i<=l;i++)tree[i]=0;
    for(int i=1;i<=m;i++){
        cin>>u>>v;
        for(int i=u;i<=v;i++)
        if(tree[i]==0){
            tree[i]++;  
        }
    }
     for(int i=0;i<=l;i++)
        if(tree[i]==0)
            cnt++;
    cout<<cnt;
    return 0;
}

by y1219323890 @ 2024-01-14 23:10:15

#include <iostream>
using namespace std;
int main(){
  int i,j,k,m,n,l,sum=0;
  int a[10001],q,z;
   cin>>l>>m;
  for(i=0;i<=l;i++)a[i]=0;
  for(i=1;i<=m;i++)
  { 
      cin>>q>>z;     
      for(j=q;j<=z;j++)if(a[j]==0)a[j]++; } 
      for(i=0;i<=l;i++)if(a[i]==0)sum++;
      cout<<sum;
  }

by Zemu_Ooo @ 2024-01-15 00:16:46

@y1219323890 您真的初始化 cnt 了嘛(


|