标签:
#include<bits/stdc++.h> using namespace std; const int maxn = 1e4; struct Meeting{ int st,en,idx; }meets[maxn]; bool cmp(Meeting a,Meeting b){ //对会议结束时间从小到大排序 return a.en < b.en; } int ans[maxn]; int main(){ int n; scanf("%d",&n); for(int i = 1; i <= n; i++){ scanf("%d%d",&meets[i].st,&meets[i].en); meets[i].idx = i; } sort(meets+1,meets+1+n,cmp); //一定选择第一个最先结束的会议 int id = 1; int cn = 1; ans[cn] = 1; for(int i = 2; i <= n; i++){ if(meets[i].st >= meets[id].en){ id = i; cn++; ans[cn] = meets[i].idx; } } printf("最多可以有%d个会议按时举行\n",cn); for(int i = 1; i <= cn; i++){ printf("%d ",ans[i]); } return 0; } /* 11 1 4 3 5 0 6 5 7 3 8 5 9 6 10 8 11 8 12 2 13 12 14 */
标签:
原文地址:http://www.cnblogs.com/chengsheng/p/5041592.html