测试点1错了,只有90分,求助大佬

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

m3o7o2n1 @ 2024-02-08 18:13:16

#include <stdio.h>
int main() {
    int l,n,a[100000],b[100000],i,j,c[100000],t=0;
    scanf("%d %d\n",&l,&n);
    for(i=0;i<n;i++)scanf("%d %d",&a[i],&b[i]);
    for(j=0;j<=l;j++)c[j]=1;
    for(i=0;i<n;i++){
        for(j=a[i];j<=b[i];j++){
                c[j-1]=0;
            }
    }
    for(j=0;j<=l;j++){
        if(c[j]==1)t++;
    }
    printf("%d",t);
    return 0;

}

by DFs_YYDS @ 2024-02-08 18:20:19

@m3o7o2n1 将第9行的c[j-1]=0改成c[j]=0试试


by m3o7o2n1 @ 2024-02-08 18:39:05

@DFs_YYDS 感谢!!!!!!


|