AC日记——dispatching bzoj 2809
2809: [Apio2012]dispatching
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 3290 Solved: 1740
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
0 3 3
1 3 5
2 2 2
1 2 4
2 3 1
Sample Output
HINT
如果我们选择编号为 1的忍者作为管理者并且派遣第三个和第四个忍者,薪水总和为 4,没有超过总预算 4。因为派遣了 2 个忍者并且管理者的领导力为 3,
用户的满意度为 2 ,是可以得到的用户满意度的最大值。
Source
思路:
这题不仅仅是恶心,,简直是个,,,唉,不说了。。
主席树+dfs序;
最后输出的ans是每个忍者可以派遣的忍者的个数*这个忍者的领导力的最大值;
我们思考主席树;
如何用主席树呢?
首先用dfs序跋整个树便利,记录每个点的开始的标号和最后的标号;
然后,我们开始往主席树里加点;
主席树的叶节点是排序离散后的薪水;
主席树维护两个元素,忍者的数量和花费;
然后,我们每次查询就可以了;
细节,,,
要用long long;
查询到末节点的时候,返回值是min(当前预算/当前单个忍者花费,当前忍者数量),不然40分;
来,上代码:
#include <cstdio>
#include <iostream>
#include <algorithm> #define LL long long
#define maxn 100005 using namespace std; struct TreeNodeType {
LL l,r,dis,sum;
};
struct TreeNodeType tree[maxn*]; struct EdgeType {
LL to,next;
};
struct EdgeType edge[maxn<<]; LL if_z,n,m,head[maxn],cost[maxn],lead[maxn];
LL cnt,hash[maxn],root[maxn],tot,start[maxn],end[maxn];
LL ans=,size; char Cget; inline void read_int(LL &now)
{
if_z=,Cget=getchar(),now=;
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} inline void edge_add(LL from,LL to)
{
cnt++;
edge[cnt].to=to;
edge[cnt].next=head[from];
head[from]=cnt;
} void tree_build(LL now,LL l,LL r)
{
if(l==r) return ;
LL mid=(l+r)>>;
tree[now].l=++tot;
tree_build(tree[now].l,l,mid);
tree[now].r=++tot;
tree_build(tree[now].r,mid+,r);
} void tree_add(LL pre,LL now,LL pos,LL l,LL r)
{
tree[now].dis=tree[pre].dis+;
tree[now].sum=tree[pre].sum+hash[pos];
if(l==r) return ;
LL mid=(l+r)>>;
if(pos<=mid)
{
tree[now].l=++tot;
tree_add(tree[pre].l,tree[now].l,pos,l,mid);
tree[now].r=tree[pre].r;
}
else
{
tree[now].r=++tot;
tree_add(tree[pre].r,tree[now].r,pos,mid+,r);
tree[now].l=tree[pre].l;
}
} void Search(LL now,LL fa)
{
start[now]=cnt++,root[cnt]=++tot;
LL pos=lower_bound(hash+,hash+size+,cost[now])-hash;
tree_add(root[cnt-],root[cnt],pos,,size);
for(LL i=head[now];i;i=edge[i].next)
{
if(edge[i].to==fa) continue;
Search(edge[i].to,now);
}
end[now]=cnt;
} LL tree_query(LL pre,LL now,LL pos,LL l,LL r)
{
if(l==r) return min(pos/hash[l],tree[now].dis-tree[pre].dis);
LL pos_=tree[tree[now].l].dis-tree[tree[pre].l].dis;
LL mid=(l+r)>>,dis_=tree[tree[now].l].sum-tree[tree[pre].l].sum;
if(pos<=dis_) return tree_query(tree[pre].l,tree[now].l,pos,l,mid);
else return tree_query(tree[pre].r,tree[now].r,pos-dis_,mid+,r)+pos_;
} int main()
{
read_int(n),read_int(m);
LL bi,master;
for(LL i=;i<=n;i++)
{
read_int(bi),read_int(cost[i]),read_int(lead[i]);
edge_add(bi,i),edge_add(i,bi),hash[i]=cost[i];
if(bi==) master=i;
}
sort(hash+,hash+n+);
size=unique(hash+,hash+n+)-hash-;
root[]=++tot;
tree_build(root[],,size);
cnt=,Search(master,);
for(LL i=;i<=n;i++)
{
LL pos=tree_query(root[start[i]],root[end[i]],m,,size);
ans=max(ans,lead[i]*pos);
}
cout<<ans<<endl;
return ;
}
AC日记——dispatching bzoj 2809的更多相关文章
- AC日记——旅游 bzoj 2157
2157 思路: LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 400005 #define IN ...
- AC日记——codevs1688求逆序对
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
- BZOJ 2809: [Apio2012]dispatching( 平衡树 + 启发式合并 )
枚举树上的每个结点做管理者, 贪心地取其子树中薪水较低的, 算出这个结点为管理者的满意度, 更新答案. 用平衡树+启发式合并, 时间复杂度为O(N log²N) ------------------- ...
- 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 ...
- BZOJ 2809 APIO2012 dispatching Treap+启示式合并 / 可并堆
题目大意:给定一棵树,选定一棵子树中的一些点,薪水和不能超过m,求点的数量*子树根节点的领导能力的最大值 考虑对于每一个节点,我们维护一种数据结构,在当中贪心寻找薪金小的雇佣. 每一个节点暴力重建一定 ...
- BZOJ - 2809 dispatching 主席树+dfs序
在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同时增强忍者们的 ...
- BZOJ 2809: [Apio2012]dispatching(左偏树)
http://www.lydsy.com/JudgeOnline/problem.php?id=2809 题意: 思路:最简单的想法就是枚举管理者,在其子树中从薪水低的开始选起,但是每个节点都这样处理 ...
- BZOJ 2809 [Apio2012]dispatching(斜堆+树形DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2809 [题目大意] 给出一棵树,求出每个点有个权值,和一个乘算值,请选取一棵子树, 并 ...
随机推荐
- ubuntu下RedisDesktopManager的安装,redis可视化工具
官方网站:https://redisdesktop.com/download 一句命令行解决: sudo snap install redis-desktop-manager 或者直接通过软件管理中心 ...
- Python使用gevent实现协程
Python中多任务的实现可以使用进程和线程,也可以使用协程. 一.协程介绍 协程,又称微线程.英文名Coroutine.协程是Python语言中所特有的,在其他语言中没有. 协程是python中另外 ...
- redis的字符串操作以及在django中的使用
redis ----redis.MongoDB : 非关系型数据库 redis 存储在内存中 MongoDB 存储在硬盘中 l 简介 redis是一个key-value存储系统 , 支持持久化 ...
- bootmem_init_node
static unsigned long __init bootmem_init_node(int node, struct meminfo *mi) in arch/arm/mm/init.c 1. ...
- 通过Proxool配置访问数据库的要点
proxool 配置的时候有Proxool.properties 或者 Proxool.xml 两种方式初始化. 我的配置环境是 myEclipse10+tomcat6.0 + mysql5.0 . ...
- 《小团团团队》第九次团队作业:Beta冲刺与验收准备
项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 实验十三 团队作业9:Beta冲刺与团队项目验收 团队名称 小团团团队 作业学习目标 (1)掌握软件黑盒测试技术:(2)学 ...
- Ext.js给form加背景图片
{ iconCls: 'zyl_icons_showdetail', tooltip: '查看', handler: function(gridView, rowIndex, colIndex) { ...
- 紫书第三章训练1 E - DNA Consensus String
DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...
- 1.ABP使用boilerplate模版创建解决方案
1.到ABP框架的官网(http://www.aspnetboilerplate.com/),自动生成一个解决方案 每步注解: 第一步:AngularJS是一款比较火的SPA(Single Page ...
- BZOJ2302 [HAOI2011]Problem c 【dp】
题目 给n个人安排座位,先给每个人一个1~n的编号,设第i个人的编号为ai(不同人的编号可以相同),接着从第一个人开始,大家依次入座,第i个人来了以后尝试坐到ai,如果ai被占据了,就尝试ai+1,a ...