HDU 2037 今年暑假不AC 題解
阿新 • • 發佈:2018-12-16
由題意得:
1..結構體排序
2.關鍵點在 結束時間
3.程式碼如下:
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; struct pro { int s,e; } time[100]; bool cmp(pro a, pro b) { return a.e<b.e; } int main() { int n,i; while(cin>>n&&n) { for(i=0; i<n; i++) cin>>time[i].s>>time[i].e; sort(time,time+n,cmp); int count=0,last_end=-1; for(i=0; i<n; i++) { if(time[i].s>=last_end) { count++; lastend=time[i].e; } } cout<<count<<endl; } return 0; }