最高70分,求各位大佬指点迷津,具体问题我在代码区写了注释,谢谢各位

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

bbluele @ 2023-07-07 14:40:28

#include<iostream>
using namespace std;
int z[10001], l, m, i, j, u, v, n;
int main()
{
    cin >> l >> m;
    for (i = 0; i < m; i++)
    {
        cin >> u >> v;
        for (j = 0; j < l; j++)
        {
            if (j > u-1 && j < v+1)
            {
                z[j] = 1;
            }
        }
    }
    for (i = 0; i < l; i++)
    {
        if (z[i] == 1)
        {
            n++;
        }
    }
    cout << l - n + 1;
    //这个前三个点过不了,而下面这个只有前三个点能过;
    //cout<<l-n;
}

by rnf5114 @ 2023-07-07 14:44:49

@bbluele 应该是≤l


by rnf5114 @ 2023-07-07 14:45:02

@bbluele

#include<iostream>
using namespace std;
int z[10010], l, m, u, v, n;
int main()
{
    cin >> l >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> u >> v;
        for (int j = 0; j <= l; j++)
        {
            if (j >=u && j <=v)
            {
                z[j] = 1;
            }
        }
    }
    for (int i = 0; i <= l; i++)
    {
        if (z[i] == 1)
        {
            n++;
        }
    }
    cout << l - n + 1;
    //这个前三个点过不了,而下面这个只有前三个点能过;
    //cout<<l-n;
}

by rnf5114 @ 2023-07-07 14:45:13

求关


|