BZOJ2809(Apio2012)[dispatching]--左偏树
来源:互联网 发布:支配集网络matlab算法 编辑:程序博客网 时间:2024/06/05 00:59
【链接】
bzoj2809
【题目大意】
给你一个n表示忍者的个数,和m表示薪水的总预算。对于每个忍者i,给出BI表示忍者i的上级,Ci表示忍者i的薪水,Li表示忍者i的领导力。
【解题报告】
这题其实对于每个忍者和他的下级和下下级以及下下下级与下*?级,可以将他们的整体抽象成一棵树,忍者就是树上的节点。所以这题就是水水的左偏树了。
#include<cstdio>#include<cstring>#include<algorithm> #define LL long longusing namespace std;const int maxn=100005;int n,m,p[maxn];LL ans,sum[maxn];struct wjd{ int x,v,p,id; bool operator < (const wjd &a)const{ return x<a.x; } }a[maxn];struct Ztree{ Ztree* son[2]; int x,dis;}tem[maxn],*ro[maxn],*Null=tem,*len=Null;inline int Read(){ int res=0; char ch=getchar(); while (ch<'0'||ch>'9') ch=getchar(); while (ch>='0'&&ch<='9') res=res*10+ch-48,ch=getchar(); return res;}void New(Ztree* &k,int x){ k=++len; k->x=x; k->dis=0; k->son[0]=k->son[1]=Null;}Ztree* Join(Ztree* a,Ztree* b){ if (a==Null) return b; if (b==Null) return a; if (a->x<b->x) swap(a,b); a->son[1]=Join(a->son[1],b); if (a->son[0]->dis<a->son[1]->dis) swap(a->son[0],a->son[1]); if (a->son[1]==Null) a->dis=0; else a->dis=a->son[1]->dis+1; return a; }Ztree* Delete(Ztree* a){ return Join(a->son[0],a->son[1]);}int main(){ freopen("2809.in","r",stdin); freopen("2809.out","w",stdout); n=Read(); m=Read(); ans=0; for (int i=1; i<=n; i++) a[i]=(wjd){Read(),Read(),Read(),i}; sort(a+1,a+1+n); a[0]=(wjd){0,0,0,0}; for (int i=0,x; i<=n; i++) x=a[i].id,New(ro[x],a[i].v),sum[x]=a[i].v,p[x]=1; for (int i=n; i>=1; i--) { int x=a[i].id; while (sum[x]>m) sum[x]-=ro[x]->x,p[x]--,ro[x]=Delete(ro[x]); ans=max(ans,(LL)a[i].p*p[x]); ro[a[i].x]=Join(ro[a[i].x],ro[x]); sum[a[i].x]+=sum[x]; p[a[i].x]+=p[x]; } printf("%lld",ans); return 0;}
阅读全文
0 0
- Bzoj2809:[Apio2012]dispatching:左偏树
- [APIO2012]bzoj2809 dispatching 左偏树
- BZOJ2809(Apio2012)[dispatching]--左偏树
- bzoj2809 [Apio2012]dispatching(左偏树)
- BZOJ2809 [APIO2012]dispatching-左偏树-左偏树学习笔记
- 【APIO2012】【BZOJ2809】派遣dispatching
- bzoj2809: [Apio2012]dispatching
- bzoj2809: [Apio2012]dispatching
- bzoj2809: [Apio2012]dispatching
- bzoj2809【APIO2012】dispatching
- 【bzoj2809】 Apio2012—dispatching
- 【APIO2012】bzoj2809 dispatching
- 【bzoj2809】[Apio2012]dispatching
- bzoj2809 [Apio2012]dispatching
- BZOJ2809: [Apio2012]dispatching
- [BZOJ2809] [Apio2012]dispatching
- bzoj2809 [Apio2012]dispatching
- bzoj2809 [Apio2012]dispatching
- 机器学习之-最邻近算法(Nearest Neighbor)
- Scala方法定义,方法和函数的区别,将方法转换成函数
- 找假币算法
- mac Android Studio安装kotlin插件
- 本人2011级学生TXH大佬写的超短的SAP网络流程序
- BZOJ2809(Apio2012)[dispatching]--左偏树
- 欢迎使用CSDN-markdown编辑器
- C#184课的主要内容
- SSM整合之参数绑定
- 异常
- linq to sql
- LeetCode-2. Add Two Numbers
- css实战之css画图
- 面试题35—第一个只出现一次的字符