题目地址:http://codeforces.com/contest/597/problem/B
和洛谷P1803一模一样,之前写过的题解:https://renjikai.com/luogu-p1803/
耻辱啊,还要看原来的题解……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<iostream> #include<algorithm> using namespace std; struct ss{ int s,e; bool operator < (ss s2){ if(e!=s2.e)return e<s2.e; else return s>s2.s; } }sa[500005]; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>sa[i].s>>sa[i].e; } sort(sa+1,sa+1+n); int cnter=0,t=0; for(int i=1;i<=n;i++){ if(sa[i].s>t){ cnter++; t=sa[i].e; } } cout<<cnter; } |