贪心之活动选择问题
將活動按照結束時間單調遞增排序
?
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;struct node {int b,e; }a[1000],temp;int cmp(node x,node y) {return x.e<y.e; }int main() {int i,j,n,p,q,x;while(~scanf("%d",&n)){int count=0;for(i=0;i<n;i++)scanf("%d%d",&a[i].b,&a[i].e);sort(a,a+n,cmp);x=a[0].e;for(j=1;j<n;j++){if(a[j].b>=x) //如果開始時間等于前一個結束時間,就可以舉辦 {count++;x=a[j].e;}}printf("%d\n",count+1); //+1是因為,x是從第一個結束時間開始的,那么他肯定舉辦了第一次 }return 0; }/** 5 1 3 2 5 4 7 6 9 8 10 **/?
轉載于:https://www.cnblogs.com/Fy1999/p/9030237.html
總結
- 上一篇: 【Apache】Apache ab压力测
- 下一篇: codeforces 453C Litt