HDU 1051 Wooden Sticks 贪心
2013-08-13 18:47
531 查看
题意理解错了,这个题是找有多少个递增的子列,并不是第一次的sticks是(1,2),只要是后面的stick的len>1,wei>2就可以了,应该是后面是stick1<stick2<stick3.
#include<cstdio> #include<iostream> #include<cstring> #include<set> #include<algorithm> #define MAXN 5010 using namespace std; struct node { int len,wei,sum; bool operator <(const node &th) const { if(len==th.len) return th.wei>wei; else return th.len>len; } }; node stick[MAXN]; int main() { // freopen("in.txt","r",stdin); int cas,n; cin>>cas; while(cas--) { cin>>n; for(int i=0; i<n; i++) { int a,b; cin>>a>>b; stick[i].len=a,stick[i].wei=b,stick[i].sum=a+b; } sort(stick,stick+n); int time=0; int vis[MAXN]; memset(vis,0,sizeof(vis)); while(1) { int flag=0; for(int i=0; i<n; i++) { if(!vis[i]) { time++; flag=1; vis[i]=1; int temp=stick[i].wei; for(int j=i+1; j<n; j++) if(stick[j].wei>=temp&&!vis[j]) { vis[j]=1; temp=stick[j].wei; } break; } } if(!flag) break; } cout<<time<<endl; } return 0; }
相关文章推荐
- 【贪心专题】HDU 1051 Wooden Sticks (切割木棍)
- HDU 1051 Wooden Sticks 贪心
- HDU 1051 Wooden Sticks 贪心+暴力
- HDU 1051 Wooden Sticks 贪心
- 【HDU】1051 - Wooden Sticks(贪心 & 二分 || 动态规划)
- HDU -- 1051 Wooden Sticks(贪心)
- hdu 1051 Wooden Sticks(贪心)
- HDU 1051 Wooden Sticks (贪心)
- HDU 1051 Wooden Sticks (简单贪心)
- HDU 1051 Wooden Sticks 贪心题解
- hdu 1051 Wooden Sticks(贪心)
- hdu 1051 Wooden Sticks(贪心策略)
- HDU-1051Wooden Sticks --贪心
- HDU 1051 Wooden Sticks (贪心)
- HDU 1051 Wooden Sticks 贪心
- HDU 1051 Wooden Sticks (贪心)
- hdu1051 Wooden Sticks (贪心)
- hdu 1051 Wooden Sticks(贪心)
- HDU1051 Wooden Sticks(贪心)
- hdu 1051 (贪心)Wooden Sticks