得了70分,请求帮助

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

small_Dongpo @ 2023-02-05 16:04:41

我的代码:

#include <iostream>
#include <cstring>
using namespace std;

bool t[10000];

int main()
{
    int l, m, cnt = 0;
    cin >> l >> m;
    memset(t, 1, sizeof(t));
    for (int i = 1; i <= m; ++i)
    {
        int a, b;
        cin >> a >> b;
        for (int i = a; i <= b; ++i)
        {
            t[i] = 0;
        }
    }
    for (int i = 0; i <= l; ++i)
    {
        if (t[i]) cnt++;
    }
    cnt++;
    cout << cnt;
}

by Konjac_WGR @ 2023-02-05 16:08:13

数组大小开小了,假如 l=10^4 你就错了


by Dr_Glitch @ 2023-02-05 16:11:31

@Howson_20120405 循环变量重复了

for (int i = 1; i <= m; ++i)
{
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; ++i)
    {
        t[i] = 0;
     }
}

你这两个都是 i


by small_Dongpo @ 2023-02-05 16:13:21

谢谢两位为我解答问题


by small_Dongpo @ 2023-02-05 16:20:00

我现在AC了


|