uva12186 Another Crisis
题目大意:
世界危机发生了,工人们请求加薪。一个老板和n个员工组成树状结构,每个员工都有自己的唯一上司,Boss的编号为0,员工1~n,工人们打算签署一个志愿书给老板,但无法跨级,当一个中级员工(非是工人的员工)的直属下属中不小于T%的人签字时,他也会签字并且递给他的直属上司,问:要让Boss收到请愿书至少需要多少个工人签字
/*
设d[u]表示让u给上级发信至少需要多少个工人。假设u有k个子节点,则至少需要C=(kT-1)100+1的直接下属发信才行。把所有的子节点的d值从小到大排序,前C个加起来即可。时间复杂度:O(nlogn)
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 100010
int n,t,num,head[maxn];
struct node{
int to,pre;
}e[maxn];
void Insert(int from,int to){
e[++num].to=to;
e[num].pre=head[from];
head[from]=num;
}
int dfs(int now){
int tmp[maxn],cnt=,res=;
bool flag=;//判断是否是叶子节点
for(int i=head[now];i;i=e[i].pre){
int to=e[i].to;
tmp[++cnt]=dfs(to);
flag=;
}
if(!flag)return ;
sort(tmp+,tmp+cnt+);
int limit=(cnt*t-)/+;
for(int i=;i<=limit;i++)res+=tmp[i];
return res;
}
int main(){
//freopen("Cola.txt","r",stdin);
while(){
scanf("%d%d",&n,&t);
memset(e,,sizeof(e));
memset(head,,sizeof(head));
num=;
if(n==&&t==)return ;
int x;
for(int i=;i<=n;i++){
scanf("%d",&x);
Insert(x,i);
}
printf("%d\n",dfs());
}
}
uva12186 Another Crisis的更多相关文章
- UVA-12186 Another Crisis 树形dp
题目链接:https://cn.vjudge.net/problem/UVA-12186 题意 给出n, T和一棵树,树上每个节点需要选择T%个直属子节点. 问根节点一共需要选择几个节点. 思路 思路 ...
- UVA-12186 Another Crisis (树状DP)
题目大意:一家工厂,一个老板(编号为0),n个工人(编号1~n),其中,有的工人是中层领导,管辖一部分其他工人.现在大家要签署一份加薪申请书,但是按照规定不能越级上访,所以只能通过一层层的中间领导传到 ...
- UVa12186:Another Crisis(树形DP)
一道简单的树形DP送给你. A couple of years ago, a new world wide crisis started, leaving many people with econo ...
- 题解 UVA12186 【工人的请愿书 Another Crisis】
俺太难了 记录一下我调了一个小时的错误 多测不清空 多测清空只清空了\(vector\) 多测全清空了,但是忘了清空\(vector[0]\) \(priority\)_ \(queue\)把\(gr ...
- UVA12186 工人的请愿书 Another Crisis (树形DP)
dp[i]表示要让i向上级发请愿书,最少需要多少个工人递交请愿书,因为要取前T%最小的,所以还要将i的子节点排序(这里用vector实现),取前c个最小的作为dp[i]的值. 这里用dfs可以省去dp ...
- HDU 3749 Financial Crisis
Financial Crisis 题意:给一个图,包含N ( 3 <= N <= 5000 )个点, M ( 0 <= M <= 10000 )条边 and Q ( 1 < ...
- Crisis of HDU(母函数)
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- (3)The critical role librarians play in the opioid crisis
https://www.ted.com/talks/chera_kowalski_the_critical_role_librarians_play_in_the_opioid_crisis 00:1 ...
- 每日英语:KFC's Crisis in China Tests Ingenuity of Man Who Built Brand
Sam Su for years ran one of the highest-flying foreign business operations in China. These days, he' ...
随机推荐
- Java7、Java8 安装卸载问题
win7 系统,同时安装了JDK7和JDK8,卸载了JDK8之后,cmd命令行输入:java -version ,本以为显示java版本1.7,结果弹错:has value '1.7',but '1. ...
- 【总结】性能调优:JVM内存调优相关文章
[总结]性能调优:JVM内存诊断工具 [总结]性能调优:CPU消耗分析 [总结]性能调优:消耗分析 JVM性能调优
- Java for LeetCode 087 Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- 服务器安装tensorflow导入模块报错Illegal instruction (core dumped)
在ubuntu上安装tensorflow后导入模块显示Illegal instruction (core dumped) 服务器的版本是Ubuntu 16.04.5 降低版本,成功导入模块 pip3 ...
- 使用wepy 小程序授权点击取消授权失败的方案
在wepy里使用进行小程序页面授权,里面包含了用户点击取消的重新授权方案: //auth.js /* * @Author: Porco_Mar * @Date: 2018-04-11 15:49:55 ...
- interceptors
<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean ...
- 分享知识-快乐自己:Hibernate对象的三种状态
图解: 1):瞬时状态(Transient) 对象与session没有关联,数据库中没有对应的数据. 一般new出来的对象便是瞬时对象. 对瞬时对象使用save()方法便使之成为持久对象. 由于数据库 ...
- 洛谷P2530 [SHOI2001]化工厂装箱员
题目描述 118号工厂是世界唯一秘密提炼锎的化工厂,由于提炼锎的难度非常高,技术不是十分完善,所以工厂生产的锎成品可能会有3种不同的纯度,A:100%,B:1%,C:0.01%,为了出售方便,必须把不 ...
- 洛谷 P1496 火烧赤壁
题目描述 曹操平定北方以后,公元208年,率领大军南下,进攻刘表.他的人马还没有到荆州,刘表已经病死.他的儿子刘琮听到曹军声势浩大,吓破了胆,先派人求降了. 孙权任命周瑜为都督,拨给他三万水军,叫他同 ...
- 自动拆装箱(int,Integer)
包装类型Java语言是一个面向对象的语言,但是Java中的基本数据类型却是不面向对象的,这在实际使用时存在很多的不便,为了解决这个不足,在设计类时为每个基本数据类型设计了一个对应的类进行代表,这样八个 ...