第一的WA,其余OK,why?

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

gordon321 @ 2023-06-09 14:04:09

include<bits/stdc++.h>

using namespace std; int main(){ int a,b,ans=1; int t,w; cin>>a>>b; int x[a+1]={0}; for(int i=0;i<b;i++){ cin>>t>>w; for(int i=t;i<=w;i++){ //cout<<i<<endl; x[i]=1; } } for(int i=1;i<=a;i++){ if(x[i]==0){ //cout<<"x"<<i<<"x"<<endl; ans++; }else{ //cout<<"0"; } } cout<<ans; return 0;
}


by gordon321 @ 2023-06-09 14:04:57

include<bits/stdc++.h>

using namespace std; int main(){ int a,b,ans=1; int t,w; cin>>a>>b; int x[a+1]={0}; for(int i=0;i<b;i++){ cin>>t>>w; for(int i=t;i<=w;i++){ //cout<<i<<endl; x[i]=1; } } for(int i=1;i<=a;i++){ if(x[i]==0){ //cout<<"x"<<i<<"x"<<endl; ans++; }else{ //cout<<"0"; } } cout<<ans; return 0;
}


by gordon321 @ 2023-06-09 14:05:29

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=1;
    int t,w;
    cin>>a>>b;
    int x[a+1]={0};
    for(int i=0;i<b;i++){
        cin>>t>>w;
        for(int i=t;i<=w;i++){
            //cout<<i<<endl;
            x[i]=1;
        }
    } 
    for(int i=1;i<=a;i++){
        if(x[i]==0){
            //cout<<"x"<<i<<"x"<<endl;
            ans++;
        }else{
            //cout<<"0";
        }
    } 
    cout<<ans;
    return 0;   
}

by nsu22010220307 @ 2023-07-20 10:28:58

这个题是从0开始算的,a[0]也有颗树


|