第一个点WA其他全部AC

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

tqttqt @ 2022-10-17 22:33:37


#include<stdio.h>

int main(void) {int sz[10001];
    for (int i = 0;i < 10001;i++)
        sz[i] = 0;
    int l, u, v,m,num=0;
    scanf("%d%d", &l, &m);

    for (int i = 0;i < m;i++)
    {
        scanf("%d%d",&u,&v);
        for (int j = u-1;j < v;j++)
            sz[j] = 1;
    }
    for (int i = 0;i < l;i++)
        if (sz[i] == 1)
            num += 1;
    printf("%d", l-num+1);
    return 0;
}

by ryf_loser @ 2022-10-17 22:58:40

@tqttqt

#include <bits/stdc++.h>
using namespace std;
bool t[10005];
int j[105],n[105];
int main(){
//freopen ("tree.in","r",stdin);
//freopen ("tree.out","w",stdout);
int l,m,i,x=0,y=0,z=0;
scanf ("%d %d",&l,&m);
for (i=1;i<=m;i++)
scanf ("%d %d",&j[i],&n[i]);
for (i=0;i<=l;i++) t[i]=1;
for (;m>0;m--){
    x=j[m];
    y=n[m];
    for (;x<=y;x++){
        t[x]=0;
    }
}
for (i=0;i<=l;i++){
    if (t[i])
    ++z;
}
printf ("%d",z);
return 0;
}

by tqttqt @ 2022-10-18 09:34:33

@ryf20100124 我的是C语言


by skq1142 @ 2022-10-18 13:25:06

我和你差不多,也找不到问题。

#include<stdio.h>
int main()
{
    int a,b,S[1005]={0};
    scanf("%d%d",&a,&b);

    int b1,b2,i;
    for(i=0;i<b;i++)
    {
        scanf("%d%d",&b1,&b2);
        int j;
        for(j=b1;j<=b2;j++)
        {
            S[j]=1;
        }
    }

    int k,y=0;
    for(k=0;k<=a;k++)
    {
        if(S[k]==0)
        y++;
    }

    printf("%d",y);
    return 0;
}

by skq1142 @ 2022-10-18 13:30:14

@skq1142 我把数组扩充了后过了


|