标签:ali 有一个 limit include 输出 class mic 比赛 other
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 81858 Accepted Submission(s): 43754
#include<iostream> #include<algorithm> using namespace std; struct S{ int a,b; }s[101]; //需要利用结构体 bool cmp(S a,S b){ if(a.a == b.a){ return a.b < b.b; } else{ return a.a < b.a; } } //贪心算法 int main(){ int n; while(cin>>n&&n){ int i,sum=1; for(i = 0;i < n;i++){ cin>>s[i].a>>s[i].b; } sort(s,s+n,cmp); int k = s[n-1].a; for(int i = n-2;i>=0;i--){ if(s[i].b <= k){ sum++; k = s[i].a; } } printf("%d\n",sum); } return 0; }
标签:ali 有一个 limit include 输出 class mic 比赛 other
原文地址:https://www.cnblogs.com/Weixu-Liu/p/10292289.html