求助:为什么我的结果是297?正确答案298。

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

CSU_Liutong_2202 @ 2024-02-13 11:01:11

#include<stdio.h>
int main() {
    int l, m, i;
    scanf("%d %d", &l, &m);
    int flag[10000] = {};
    int u, v, j;
    for (i = 1; i <= m; i++) {
        scanf("%d %d", &u, &v);
        for (j = u; j <=v; j++) {
            flag[j] = 1;
        }
    }
    int n = 0;
    for (i = 0; i < l; i++) {
        if (flag[i] == 0) {
            n++;
        }
    }
    printf("%d", n);
    return 0;
}

by jeffstart @ 2024-02-13 11:06:15

@CSU_Liutong_2202 应该是 \le l,而不是 < l


by CSU_Liutong_2202 @ 2024-02-13 11:31:02

@jeffstart 谢谢。


|