90分求助呜呜

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

wjk_bailan @ 2023-08-10 13:59:39

第九个测试点WA 我自己测试时答案好像没问题啊

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main()
{
    int l, m, a[10001], b[101][2], s = 0;
    scanf("%d %d", &l, &m);
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= 2; j++)
        {
            scanf("%d", &b[i][j]);
        }
        for (int p = b[i][1]; p <= b[i][2]; p++)
        {
            a[p] = 1;
        }
    }
    for (int q = 0; q <= l; q++)
    {
        if (a[q] == 1)
            s++;
    }
    int k = l + 1 - s;
    printf("%d", k);
    return 0;
}

by UchihaCelery @ 2023-08-10 14:06:01

a数组没有初始值,要定义在main外面。 代码:

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int a[10005];
int main()
{
    int l, m, b[105][3], s = 0;
    scanf("%d %d", &l, &m);
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= 2; j++)
        {
            scanf("%d", &b[i][j]);
        }
        for (int p = b[i][1]; p <= b[i][2]; p++)
        {
            a[p] = 1;
        }
    }
    for (int q = 0; q <= l; q++)
    {
        if (a[q] == 1)
            s++;
    }
    int k = l + 1 - s;
    printf("%d", k);
    return 0;
}

by wjk_bailan @ 2023-08-11 16:03:31

@UchihaCelery 谢谢大佬!\ 但是为什么有九个测试点是正确的,只有一个会出问题呢?\ 就是说有时候对有时候错实在难懂


by UchihaCelery @ 2023-08-11 16:07:26

@wjk_bailan 只能说明一件事:数据水

我也不知道我估摸是因为只有那一个数据a[0,l]中有几个随机值随机到了1但是您之前没有给他标记成1


|