HDOJ 2037 今年暑假不AC

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2037

系统的学了一下贪心,事件的调度问题。重新写了一下。

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 using namespace std;
 6 
 7 const int MAXN=120;
 8 
 9 pair<int,int> show[MAXN];
10 
11 bool cmp(pair<int,int>a,pair<int,int>b){
12     return a.second<b.second;
13 }
14 
15 
16 int solve(int N){
17     sort(show,show+N,cmp);
18     int ans=0;
19     int t=0;
20     for(int i=0;i<N;i++){
21         if(show[i].first>=t){
22             ans++;
23             t=show[i].second;
24         }
25     }
26     return ans;
27 }
28 
29 int main(){
30     int N;
31     while(cin>>N){
32         if(N==0) break;
33         for(int i=0;i<N;i++)
34             cin>>show[i].first>>show[i].second;
35         cout<<solve(N)<<endl;
36     }
37 
38 }
自己选的路,跪着也要把它走完------ACM坑
原文地址:https://www.cnblogs.com/IKnowYou0/p/6349507.html