help

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

y_yoy @ 2024-07-31 12:37:34

90分代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0,l[1000000];
    for(int i=1;i<=1000000;i++)l[i]=0;
    cin>>a>>b;
    for(int i=1;i<=b;i++){
        int g,k;
        cin>>g>>k;
        for(int p=g;p<=k;p++){
            if(l[p]!=1)l[p]=1;
        }
    }
    for(int i=1;i<=a;i++){
        if(l[i]!=1)ans++;
    }
    cout<<ans;
}

by lyh0217 @ 2024-07-31 12:56:08

@juice_cy \ AC code:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0,l[1000000];
    for(int i=1;i<=1000000;i++)l[i]=0;
    cin>>a>>b;
    for(int i=1;i<=b;i++){
        int g,k;
        cin>>g>>k;
        for(int p=g;p<=k;p++){
            if(l[p]!=1)l[p]=1;
        }
    }
    for(int i=0;i<=a;i++){
        if(l[i]!=1)ans++;
    }
    cout<<ans;
}

by y_yoy @ 2024-07-31 14:15:08

@lyh0217 谢谢!


|