第一个测试数据不对,找大神求原因

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

ACkeys @ 2022-09-06 18:26:49

#include<stdio.h>
#include <iostream>
using namespace std;
int main()
{
    int l, m;
    int u[200], v[200];
    cin >> l >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> u[i] >> v[i];
    }
    int length[100001];
    for (int i = 1; i <= l; i++)
        length[i] = 1;
    for (int i = 1; i <= m; i++)
    {
        while( u[i] <= v[i])
        {
            if (length[u[i]] != 0)
            {
                length[u[i]] = 0;
                l--;
            }
            u[i]++;
        }
    }
    cout << l+1;
    return 0;
}

by 032o35 @ 2022-09-06 18:43:01

0l,所以初始化从 0 开始。


by zhc9426 @ 2022-09-06 18:45:12

az,回晚了,14行改成i=0就行


by zhc9426 @ 2022-09-06 18:45:57

0 100,输入数据里有这么一行


by limeng911 @ 2022-09-06 20:06:44

从0开始循环

因为长l的马路是包含头(0)和尾(l)的


by ACkeys @ 2022-09-06 22:12:54

@zhc9426 非常感谢


by ACkeys @ 2022-09-06 22:13:27

@032o35 谢谢


by ACkeys @ 2022-09-06 22:14:02

@limeng911 懂了,谢谢


|