hdu Wooden Sticks
这题是暴力加贪心,算是一道水题吧!只要把l和w从小到大排个序就行了。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include"iostream" #include"stdio.h" #include"string.h" #include"cmath" #include"algorithm" #include"queue" #define mx 10005 using namespace std; struct node { int l,w; }; bool cmp(const node a,const node b) { if(a.l!=b.l) return a.l<b.l; else return a.w<b.w; } node sticks[mx],temp; int visited[mx]; bool judge(node a,node b) { if(a.l>=b.l&&a.w>=b.w) return true; return false; } int main() { int t,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; }