救救

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

OHMYXUAN @ 2023-11-14 20:18:41

#include <iostream>
using namespace std;
int main(){
    int l,m,sum=0;
    cin>>l>>m;
    int a[10000];
    for(int i=0;i<10000;i++){
        a[i]=1;
    }
    while(m--){
        int x,y;
        cin>>x>>y;
        for(int i=x;i<=y;i++){
            if(a[i]==1){
                a[i]=0;
            }
        }
    }
    for(int i=0;i<=l;i++){
        if(a[i]==1){
            sum++;
        }
    }
    cout<<sum;
    return 0;
} 

为什么只有30分


by spencer @ 2023-11-14 20:36:13

你第6行数组开小了,开到10500。 还有第七行的循环范围改成0到L


by spencer @ 2023-11-14 20:36:37

@OHMYXUAN


by tooexpensivetoattend @ 2023-11-14 20:57:55

把数组开大一点就好了


by OHMYXUAN @ 2023-11-15 08:21:31

@spencer OK got it 谢谢你


by OHMYXUAN @ 2023-11-15 08:25:57

@spencer 可是还是只有30分啊


by spencer @ 2023-11-15 13:38:34

我帮你调好了,能ac,你自己看看哪里有问题

#include <iostream>
using namespace std;
int main(){
    int l,m,sum=0;
    cin>>l>>m;
    int a[10500];
    for(int i=0;i<=l;i++){
        a[i]=1;
    }
    while(m--){
        int x,y;
        cin>>x>>y;
        for(int i=x;i<=y;i++){
            if(a[i]==1){
                a[i]=0;
            }
        }
    }
    for(int i=0;i<=l;i++){
        if(a[i]==1){
            sum++;
        }
    }
    cout<<sum;
    return 0;
} 

by spencer @ 2023-11-15 13:39:19

@OHMYXUAN


by OHMYXUAN @ 2023-11-15 18:10:13

@spencer @spencer ok了 谢谢神犇


by spencer @ 2023-11-15 18:26:48

@OHMYXUAN 给个关注呗qaq


by OHMYXUAN @ 2023-11-15 19:09:50

@spencer okey


|