Wooden Sticks
HDU -10513
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1
2
1
3
AC代码:
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct note { int u,v; }e[10000]; int cmp(note A,note B) { if(A.u!=B.u)//在长度不等时,按长度从大到小排 return A.u>B.u; else return A.v>B.v;//长度相等时,按重量从大到小排 } int n,sum,flag; int book[10000]; int main() { int T; scanf("%d",&T); while(T--) { int i,j; memset(book,0,sizeof(book)); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d",&e[i].u,&e[i].v); } sort(e,e+n,cmp); int s=0,minn; for(i=0;i<n;i++)//贪心,,按例子说:5.4.3.2.1排好后按重量排,能 { //从大到小排几组(重量),就是需要几分钟。 if(book[i]==0) { minn=e[i].v; } else continue; for(j=i+1;j<n;j++) { if(e[j].v<=minn&&book[j]==0) { book[j]=1; minn=e[j].v; } } s++; } printf("%d\n",s); } }