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 [题目大意] 给出一棵树,求出每个点有个权值,和一个乘算值,请选取一棵子树, 并 ...
随机推荐
- PHP数组函数 array_multisort() ----对多个数组或多维数组进行排序
PHP中array_multisort可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序. 关联(string)键名保持不变,但数字键名会被重新索引. 输入数组被当成一个表的列并以 ...
- linux系统入门—文件管理
目录 linux系统入门-文件管理 系统目录结构 目录管理 linux系统入门-文件管理 系统目录结构 几乎所有的计算机操作系统都是使用目录结构组织文件.具体来说就是在一个目录中存放子目录和文件,而在 ...
- day24 02 单继承(派生)
day24 02 单继承(派生) 1.首先来看一个简单的例子 比如: 狗类的属性有:吃,喝,看门 鸟类的属性有:吃,喝,下蛋 看门和下蛋就是这两种动物不同的属性,而吃喝是两个共同的属性 以下代码实现了 ...
- poj3617 best cow line(贪心题)
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32687 Accepted: 8660 De ...
- Hadoop4.2HDFS测试报告之三
第一组:文件存储写过程记录 NameNode:1 DataNode:1 本地存储 scp localpath romotepath 500 2 1 23.67 NameNode:1 DataNode: ...
- alex 推荐的书
这两本书不错, 追风筝的人<白鹿原>~~~反天不错~~~可以看下.14:27:22AndyZhang 2018-1-29 14:27:22 改变人的东西 读书.看电影.旅行.经历各种事 ...
- SPOJ COT2 Count on a tree II 树上莫队算法
题意: 给出一棵\(n(n \leq 4 \times 10^4)\)个节点的树,每个节点上有个权值,和\(m(m \leq 10^5)\)个询问. 每次询问路径\(u \to v\)上有多少个权值不 ...
- webdriver高级应用-使用JavaScript操作页面元素
Webdriver搞不定的,需要用js,无需引入有关js的包就可用 在WebDriver脚本代码中执行JavaScript代码,来实现对页面元素的操作.此方法主要用于解决在某些情况下,页面元素的.cl ...
- python - 自动化测试框架 - logger
# -*- coding:utf-8 -*- '''@project: Voctest@author: Jimmy@file: log.py@ide: PyCharm Community Editio ...
- Python面试题(练习二)
1.用Python实现一个二分查找的函数. data = [1, 3, 6, 7, 9, 12, 14, 16, 17, 18, 20, 21, 22, 23, 30, 32, 33, 35] def ...