标签:
2 2 1 10 10 11 3 1 10 10 11 11 20
1 2
按照结束的顺序排序,结束的越早之后可选的工作越多
#include <iostream> #include <algorithm> using namespace std; struct node { int start; int End; }Time[10020]; bool cmp(node a, node b) { return a.End < b.End; } int main() { int Case; cin>>Case; while(Case--) { int n; cin>>n; for(int i = 0; i < n; i++) { cin>>Time[i].start>>Time[i].End; } sort(Time,Time+n,cmp); int ans = 0,End = 0; for(int i = 0; i < n; i++) { if(End < Time[i].start) { ans++; End = Time[i].End; } } cout<<ans<<endl; } return 0; }
标签:
原文地址:http://blog.csdn.net/u013445530/article/details/42458743