[Apio2012]dispatching
[Apio2012]dispatching
时间限制: 1 Sec 内存限制: 128 MB
题目描述
1 ≤Li ≤ 1,000,000,000 忍者的领导力水平。
输入
输出
输出一个数,表示在预算内顾客的满意度的最大值。
样例输入
样例输出
提示
如果我们选择编号为 1的忍者作为管理者并且派遣第三个和第四个忍者,薪水总和为 4,没有超过总预算4。因为派遣了2个忍者并且管理者的领导力为3,用户的满意度为 2 ,是可以得到的用户满意度的最大值。
题解:
这是一道左偏树的裸题,既可以用深搜,也可以用广搜,深搜简单,广搜直观,小编用的是广搜。
建立左偏树。(用大根堆,因为只跟忍者的个数有关,所以被删除的工资越大越好)
从叶子借点向上广搜,不断合并节点,然后不断删除堆顶直到总工资小于m。
然后广搜入队的时候特判一下,一面忽略叶子节点的可能性。
一下是AC代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<ctime>
using namespace std;
int n,m;
int father[],cnt[];
long long sum[],num[],skill[];
queue<int>mem;
struct node
{
long long key;
int dist;
node *l,*r;
int ldist(){return l?l->dist:;}
int rdist(){return r?r->dist:;}
} man[];
node *pos=man,*root[];
int read()
{
int ans=,f=;
char i=getchar();
while(i<''||i>''){if(i=='-')f=-;i=getchar();}
while(i>=''&&i<=''){ans=ans*+i-'';i=getchar();}
return ans*f;
}
node* merge(node* a,node* b)
{
if(!a||!b)return a?a:b;
if(a->key<b->key)swap(a,b);
a->r=merge(a->r,b);
if(a->ldist()<a->rdist())swap(a->l,a->r);
a->dist=a->rdist()+;
return a;
}
void delet(int x)
{
num[x]--;
sum[x]-=root[x]->key;
root[x]=merge(root[x]->l,root[x]->r);
}
int main()
{
int i,j;
long long ans=;
n=read();
m=read();
for(i=; i<=n; i++)
{
father[i]=read();
cnt[father[i]]++;
scanf("%lld",&sum[i]);
pos++;
pos->key=sum[i];
pos->l=pos->r=NULL;
num[i]=;
root[i]=pos;
scanf("%lld",&skill[i]);
}
for(i=; i<=n; i++)
if(!cnt[i])
{
mem.push(i);
ans=max(ans,skill[i]);
}
while(!mem.empty())
{
int x=mem.front();
mem.pop();
int fa=father[x];
root[fa]=merge(root[fa],root[x]);
cnt[fa]--;
sum[fa]+=sum[x];
num[fa]+=num[x];
if(!cnt[fa])
{
while(sum[fa]>m)delet(fa);
ans=max(ans,skill[fa]*num[fa]);
if(father[fa])mem.push(fa);
}
}
cout<<ans<<endl;
return ;
}
[Apio2012]dispatching的更多相关文章
- 【bzoj2809】[Apio2012]dispatching 左偏树
2016-05-31 15:56:57 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2809 直观的思想是当领导力确定时,尽量选择薪水少的- ...
- BZOJ 2809: [Apio2012]dispatching( 平衡树 + 启发式合并 )
枚举树上的每个结点做管理者, 贪心地取其子树中薪水较低的, 算出这个结点为管理者的满意度, 更新答案. 用平衡树+启发式合并, 时间复杂度为O(N log²N) ------------------- ...
- bzoj2809 [Apio2012]dispatching(左偏树)
[Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 M ...
- [Apio2012]dispatching 主席树做法
bzoj 2809: [Apio2012]dispatching http://www.lydsy.com/JudgeOnline/problem.php?id=2809 Description 在一 ...
- 【BZOJ2809】[Apio2012]dispatching 可并堆
[BZOJ2809][Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 M ...
- bzoj 2809: [Apio2012]dispatching -- 可并堆
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MB Description 在一个忍者的帮派里,一些忍者们被选中派 ...
- 【BZOJ 2809】2809: [Apio2012]dispatching (左偏树)
2809: [Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Maste ...
- 2809: [Apio2012]dispatching
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MB Submit: 3102 Solved: 1641 [Sub ...
- BZOJ2809: [Apio2012]dispatching
传送门 主席树经典题. 首先把树搞出来,然后搞出来DFS序.然后离散化点权,在DFS序上建立主席树. 对于每个点对应的区间,查找对应的区间最大的点数即可. //BZOJ2809 //by Cydiat ...
随机推荐
- mongodb新人扫盲
前言 数据库基本命令 集合(表)命令 增加数据 删除数据 更新数据 使用update()更新 使用save()命令实现upsert 自动更新信息 查询数据 mongoose的使用 前言 mongodb ...
- Day5模块-time和datetime模块
模块是封装一段代码来实现某种功能. 分为三类: 1.自定义模块 2.标准库,内置模块 3.开源模块 -------------------------------------------------- ...
- carryLess开发日记_2017-05-18
1.接上一篇的form表单的ajax问题,上一篇中的form表单的ajax提交不能上传文件,所以采用了formData的方式上传 1)前段代码如下: <form action="&qu ...
- Reverse Integer 2015年6月23日
题目: Reverse digits of an integer. Example1: x = , return Example2: x = -, return - 思路:递归 解答: / test ...
- 1.WF 4.5在项目中直接使用的问题
最近公司需要在互联网产品后台进行精细化流程管理,开发了一个基于WF 4.5框架的流程引擎与图形化设计器,让流程真正的跑了起来. 基于Visual Studio 直接设计流程主要面临以下的问题: 1.需 ...
- .net操作InI文件
public class INI { public static string IniFileName = "";//路径 [DllImport("kernel32&qu ...
- Metrics
系统开发到一定的阶段,线上的机器越来越多,就需要一些监控了,除了服务器的监控,业务方面也需要一些监控服务.Metrics作为一款监控指标的度量类库,提供了许多工具帮助开发者来完成自定义的监控工作. 举 ...
- React学习小结(三)
一.React数据的传输 1.属性和状态是react中数据传递的载体 2.属性是声明以后不允许被修改的东西 3.属性只能在组件初始化的时候声明并传入组件内部,并且在组件内部通过this.props获取 ...
- 学习Spark——那些让你精疲力尽的坑
这一个月我都干了些什么-- 工作上,还是一如既往的写bug并不亦乐乎的修bug.学习上,最近看了一些非专业书籍,时常在公众号(JackieZheng)上写点小感悟,我刚稍稍瞄了下,最近五篇居然都跟技术 ...
- ASP.NET MVC5(一):ASP.NET MVC概览
ASP.NET MVC概览 ASP.NET MVC是一种构建Web应用程序的框架,它将一般的MVC(Model-View-Controller)模式应用于ASP.NET框架. 1.ASP.NET MV ...