一道很经典的贪心问题
题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=14
#include<iostream> #include<algorithm> using namespace std; struct met { int b,e; }a[]; bool comp(met x,met y) { return x.e<y.e; } int main() { int m,n,i,ans,t; cin>>m; while(m--) { ans=,t=; cin>>n; ;i<n;i++) cin>>a[i].b>>a[i].e; sort(a,a+n,comp); ;i<n;i++) { if(t<a[i].b) { ans++; t=a[i].e; } } cout<<ans<<endl; } }