2011年8月30日

hdu3916Sequence Decomposition贪心

摘要: hdu3916Sequence Decomposition贪心解:(引)比如一个序列2 3 4 3 3 1如何拆成门函数分量使得长度尽量平均呢? 直观的想法是在消的过程中使序列尽量平均。首先想到是左边第一个肯定要拆成2个门函数且应使其尽可能长,但也不是越长越好。如果a[i] <= a[i+1] 那么消掉a[i]的时候,a[i+1]消掉肯定没坏处,因为如果不消,不仅可能使答案变小,而且序列也会变的更加不平均如果a[i] > a[i+1] 则本着使序列越来越平均的思想,消掉a[i]的时候自然是不要消掉a[i+1]了。上述样例采用该贪心方法的过程是2 3 4 3 3 1 消(1,3)1 阅读全文
posted @ 2011-08-30 00:53 4.5.6 阅读(133) 评论(0) 推荐(0) 编辑

hdu2863Top Shooter

摘要: 贪心:枚举时间用范围最大的打高度最小的先按时间后按高度从低到高排列View Code #include<iostream>#include<queue>using namespace std;int sni[51];const int INF=10000000;int MIN,n,m;struct node { int t,h; node(){}; node(int _t,int _h):t(_t),h(_h){}; friend bool operator<(const node &a,const node&b) { if(a.t!=b.t)re 阅读全文
posted @ 2011-08-30 00:47 4.5.6 阅读(115) 评论(0) 推荐(0) 编辑