题解 | #剩下的树#

剩下的树

https://www.nowcoder.com/practice/f5787c69f5cf41499ba4706bc93700a2

#include <iostream>
using namespace std;

int main() {
    int L, M;
    int hashtable[10001];
    for(int i=0;i<=10000;i++)hashtable[i]=1;
    while (cin >> L >> M) { // 注意 while 处理多个 case
        for(int i=0;i<M;i++)
        {
            int a,b;
            cin>>a>>b;
            for(int i=a;i<=b;i++)hashtable[i]=0;
        }
        int count=0;
        for(int i=0;i<=L;i++)
        {
            if(hashtable[i]==1)count++;
        }
        cout<<count<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务