文章

16

粉丝

44

获赞

2

访问

4.5k

头像
剩下的树 题解:数组
P1175 清华大学上机题
发布于2024年3月17日 21:30
阅读数 186

#include <bits/stdc++.h>
using namespace std;

int main(){
    int x,m;
    while(cin>>x>>m){
        int L[10005]={0};//用0表示存在树
        int len=x+1;
        for(int i=0;i<m;i++){//
            int low,high;
            cin>>low>>high;
            for(int i=low;i<=high;i++){
                if(L[i]==1) continue;
                else L[i]=1;
            }
        }
        int cnt=0;
        for(int i=0;i<len;i++){
            if(L[i]==0) cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发