设为首页 加入收藏

TOP

BZOJ 1588 HNOI2002 营业额统计 裸Treap
2015-07-20 17:34:16 来源: 作者: 【 】 浏览:3
Tags:BZOJ 1588 HNOI2002 营业额 统计 Treap

题目大意:。。。题目描述不全看这里好了

给定一个序列 对于每个元素我们定义该数的最小波动值为这个数与前面所有数的差中的最小值(第一个数的最小波动值为第一个数本身) 求最小波动值之和

找最近的数只需要找前驱和后继就行了 平衡树的基本操作 不多说了

然后――

此题多组数据!!尼玛!!看题目描述这也是单组数据啊!!什么**情况??

而且多组数据尼玛也就算了!!输入数据还不全!!如果读到EOF需要按照0处理!尼玛这上哪里想去啊!

于是此题不看题解无法AC 鉴定完毕

60%达成 还剩四道题 水水吧。。。

#include
  
   
#include
   
     #include
    
      #include
     
       using namespace std; struct abcd{ abcd *ls,*rs; int key,num; abcd(int x); }*null=new abcd(0),*root=null; abcd :: abcd(int x) { ls=rs=null; key=rand(); num=x; } void Zig(abcd *&x) { abcd *y=x->ls; x->ls=y->rs; y->rs=x; x=y; } void Zag(abcd *&x) { abcd *y=x->rs; x->rs=y->ls; y->ls=x; x=y; } void Insert(abcd *&x,int y) { if(x==null) { x=new abcd(y); return ; } if(y==x->num) return ; if(y
      
       num) { Insert(x->ls,y); if(x->ls->key>x->key) Zig(x); } else { Insert(x->rs,y); if(x->rs->key>x->key) Zag(x); } } int Pred(abcd *x,int y) { if(x==null) return 0xefefefef; if(y
       
        num) return Pred(x->ls,y); return max( x->num , Pred(x->rs,y) ); } int Secc(abcd *x,int y) { if(x==null) return 0x7fffffff; if(y>x->num) return Secc(x->rs,y); return min( x->num , Secc(x->ls,y) ); } int n,ans; int main() { int i,x; srand(19980402); while(~scanf("%d",&n) ) { root=null;ans=0; for(i=1;i<=n;i++) { if(scanf("%d",&x)==EOF)x=0; int pred=Pred(root,x),secc=Secc(root,x); if(i^1) ans+=min( x-pred , secc-x ); else ans+=x; Insert(root,x); } cout<
        
         

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Largest Rectangular Area in a H.. 下一篇HDU-2844-Coins(多重背包)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)