This problem is violent and greedy, is a water problem it! As long as L and W from small to big row order on the line ...
#include"iostream"#include"stdio.h"#include"string.h"#include"Cmath"#include"algorithm"#include"Queue"#defineMX 10005using namespacestd;structnode{intl,w;};BOOLcmpConstNode A,ConstNode B) { if(A.L!=B.L)returna.l<B.L; Else returna.w<B.W;} Node sticks[mx],temp;intVISITED[MX];BOOLjudge (node A,node b) {if(A.L>=B.L&&A.W>=B.W)return true; return false;}intMain () {intT,n,i,j,minute; CIN>>T; while(t--) {cin>>N; Minute=0; for(i=0; i<n;i++) {cin>>sticks[i].l>>STICKS[I].W; } sort (Sticks,sticks+n,cmp); Memset (visited,0,sizeof(visited)); for(i=0; i<n;i++) { if(!visited[i]) {visited[i]=1; minute++;} Else Continue; TEMP.L=sticks[i].l;temp.w=STICKS[I].W; for(j=i+1; j<n;j++) { if(!visited[j]&&judge (Sticks[j],temp)) {Visited[j]=1; temp.l=sticks[j].l;temp.w=STICKS[J].W; } }} cout<<minute<<Endl; } return 0;}
View Code
HDU Wooden Sticks