Luogu P1276 校门外的树(增强版)

Luogu P1276 校门外的树(增强版)

本来看着是道普及-,就不打算写博客了,结果因为出了3次错,调试了15min就还是决定写一下……
本题坑点:
1.每个位置有三种情况:空穴,树苗,树(而不只有空穴和树)。
2.每个位置初始是种了树的(注意是树)。
3.第二个输出是被砍后又种上的树苗数。
总而言之,一道普及-的题都有那么多细节,所以以后真要好好读题了……

#include<bits/stdc++.h>

using namespace std;

int l,n,s,e,op,cnt1,cnt2;
int r[10010],re[10010];

int main()
{
    scanf("%d%d",&l,&n);
    for(int i=0;i<=l;i++) {
        r[i]=1;
    }
    for(int i=1;i<=n;i++) {
        scanf("%d%d%d",&op,&s,&e);
        if(op==0) {
            for(int j=s;j<=e;j++) {
                if(r[j]==2) {
                    cnt2++;
                }
                r[j]=0;
            }
        }
        else if(op==1) {
            for(int j=s;j<=e;j++) {
                if(r[j]==0) {
                    r[j]=2;
                }
            }
        }
    }
    for(int i=0;i<=l;i++) {
        if(r[i]==2) {
            cnt1++;
        }
    }
    printf("%d\n%d",cnt1,cnt2);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/luoshui-tianyi/p/11441176.html