题意:中文题面,不需要解释。
思路:按比赛结束时间从小到大排序。
AC代码:
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6+10; struct Node{ int s,e; }node[maxn]; bool cmp(Node a,Nodea b){ if(a.e==b.e){ return a.s<b.s; } return a.e<=b.e; } int main(void){ int n; cin>>n; for(int i = 1; i <= n; i++){ cin>>node[i].s>>node[i].e; } sort(node+1,node+1+n,cmp); int cnt = 1; int tem = node[1].e; for(int i = 2; i <= n; i++){ int t = node[i].s; if(t>=tem){ cnt++; tem = node[i].e; } } cout<<cnt<<endl; return 0; }