标签:
hdu 2037 今年暑假不AC
定义结构体,排序,然后贪心。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct T{ int s,e; }; T program[105]; bool cmp(struct T a,struct T b) { if(a.e != b.e) return a.e < b.e; } bool Selected[105]; int main() { int n; while(scanf("%d",&n)!=EOF && n) { for(int i = 0; i < n; i++) { scanf("%d%d",&program[i].s,&program[i].e); } sort(program,program+n,cmp); Selected[0] = true; int j = 0; for(int i = 1; i < n; i++) { if(program[i].s >= program[j].e) { Selected[i] = true; j = i; } else Selected[i] = false; } int sum = 0; for(int i = 0; i < n; i++) { if(Selected[i]) sum++; } printf("%d\n",sum); memset(Selected,0,sizeof(Selected)); memset(program,0,sizeof(program)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Pos-Proteus/p/4713601.html