(~ ̄▽ ̄) ~*
This problem uses the qsort () function of the Cstdlib library :
Usage Link: http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.html
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>using namespacestd;structstick{intl,w; intFlag;} st[5005];intcmpConst void*u,Const void*v) {Stick*a= (Stick *) U; Stick*b= (Stick *) v; if(A->l = = b->l)returnA->w-b->W; Else returnA->l-b->l;}intMain () {intcas,n,mint,w; scanf ("%d",&CAs); while(cas--) {scanf ("%d",&N); for(intI=0; i<n;i++) {scanf ("%d%d",&st[i].l,&ST[I].W); St[i].flag=0; } qsort (St,n,sizeof(st[0]), CMP);//sort from small to large, if L is equal, then W small row frontMinT=0; for(intI=0; i<n;i++) { if(!St[i].flag) {MinT++; W=ST[I].W; for(intj=i+1; j<n;j++) { if((!st[j].flag) &&st[j].w>=W) {St[j].flag=1; W=ST[J].W; } }}} printf ("%d\n", MinT); } return 0;}
POJ 1065 Wooden sticks# greedy +qsort usage