题解 P1047 【校门外的树】

可以直接模拟,用珂朵莉树是不有点小题大做。

你怎么做珂朵莉都会骂你:“这么简单的模拟都要用***”

附赠珂朵莉照片一张

另外讲几点:

可以用int,你要不怕MLE

#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    bool a[666666];//true 代表a[i]位置有树,false代表a[i]位置上的树已被砍。
    int n,m;
    cin>>n>>m;
    for(int i = 0;i<=n;++i) {//数组初始化为1,因为最开始的时候每个位置都有一棵树
        a[i] = 1;
    }
    int ans = 0;
    while(m--) {
        int start,end;
        cin>>start>>end;
        for(int j = start;j<=end;++j) {//砍树
            a[j] = 0;
        }
    }
    for(int i = 0;i<=n;++i) {
        if(a[i] == 1) {//统计剩余。
            ans++;
        }
    }
    cout<<ans;
}
posted @ 2019-03-22 12:13  littlefrog  阅读(88)  评论(0编辑  收藏  举报