#1#2#3WA70分求调

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

xingze @ 2024-02-18 16:24:47

测试结果:https://www.luogu.com.cn/record/147331152
代码:

#include <iostream>
using namespace std;
bool l[10050];
long long a,r;
int main()
{
    cin >> a;
    cin >>r;
    for (int i = 0;i<=a;i++)
        l[i]=1;
    while (r--)
    {
        long long x,y;
        cin >> x>>y;
        for (int i = x;i<=y;i++)
            l[i]=0;
    }
    long long ans;
    for (int i = 0;i<a;i++)
    {
        if (l[i])
            ans++;
    }
    cout << ans<<endl;
}

思路与ChargeDonkey的题解相似,求dalao指错!


by xingze @ 2024-02-18 16:50:09

@wenguangxi 不过我有点疑问:
1:根据您发的代码来测试,只得#1,2,3的分值
2:最后的判断应该!l[i]吧


by wenguangxi1 @ 2024-02-18 16:54:08

#include <iostream>
using namespace std;
bool l[10050];
long long a,r;
int main()
{
    cin >> a;
    cin >>r;
    for (int i = 0;i<=a;i++)
        l[i]=0;
    while (r--)
    {
        long long x,y;
        cin >> x>>y;
        for (int i = x;i<=y;i++)
            l[i]=1;
    }
    long long ans=0;
    for (int i = 0;i<=a;i++)
    {
        if (!l[i])
            ans++;
    }
    cout << ans<<endl;
}

by liuzilin114514 @ 2024-02-18 16:55:01

@xinge

#include <iostream>
using namespace std;
bool l[10050];
long long a,r;
int main()
{
    cin >> a;
    cin >>r;
    for (int i = 0;i<=a;i++)
        l[i]=0;
    while (r--)
    {
        long long x,y;
        cin >> x>>y;
        for (int i = x;i<=y;i++)
            l[i]=1;
    }
    long long ans=0;
    for (int i = 0;i<=a;i++)
    {
        if (!l[i])
            ans++;
    }
    cout << ans;
}

by xingze @ 2024-02-18 16:59:13

thx,此贴结


上一页 |