题目大意:

世界危机发生了,工人们请求加薪。一个老板和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的更多相关文章

  1. UVA-12186 Another Crisis 树形dp

    题目链接:https://cn.vjudge.net/problem/UVA-12186 题意 给出n, T和一棵树,树上每个节点需要选择T%个直属子节点. 问根节点一共需要选择几个节点. 思路 思路 ...

  2. UVA-12186 Another Crisis (树状DP)

    题目大意:一家工厂,一个老板(编号为0),n个工人(编号1~n),其中,有的工人是中层领导,管辖一部分其他工人.现在大家要签署一份加薪申请书,但是按照规定不能越级上访,所以只能通过一层层的中间领导传到 ...

  3. UVa12186:Another Crisis(树形DP)

    一道简单的树形DP送给你. A couple of years ago, a new world wide crisis started, leaving many people with econo ...

  4. 题解 UVA12186 【工人的请愿书 Another Crisis】

    俺太难了 记录一下我调了一个小时的错误 多测不清空 多测清空只清空了\(vector\) 多测全清空了,但是忘了清空\(vector[0]\) \(priority\)_ \(queue\)把\(gr ...

  5. UVA12186 工人的请愿书 Another Crisis (树形DP)

    dp[i]表示要让i向上级发请愿书,最少需要多少个工人递交请愿书,因为要取前T%最小的,所以还要将i的子节点排序(这里用vector实现),取前c个最小的作为dp[i]的值. 这里用dfs可以省去dp ...

  6. HDU 3749 Financial Crisis

    Financial Crisis 题意:给一个图,包含N ( 3 <= N <= 5000 )个点, M ( 0 <= M <= 10000 )条边 and Q ( 1 < ...

  7. Crisis of HDU(母函数)

    Crisis of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. (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 ...

  9. 每日英语: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' ...

随机推荐

  1. 在pycharm中执行脚本没有报错但输出显示Redirection is not supported.

    没有新式语法错误,但是输出显示Redirection is not supported.(不支持重定向) 在stockflow中找到是因为从IDE中运行脚本的原因,比如pycharm,所有IDE都提供 ...

  2. vue 组件与传值

    一.表单输入绑定(v-model 指令) 可以用 v-model 指令在表单 <input>.<textarea> 及 <select> 元素上创建双向数据绑定. ...

  3. HDU - 4990 Reading comprehension 【矩阵快速幂】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4990 题意 初始的ans = 0 给出 n, m for i in 1 -> n 如果 i 为奇 ...

  4. PAT天梯赛 L2-020. 功夫传人 【DFS】

    题目链接 https://www.patest.cn/contests/gplt/L2-020 思路 从师父开始 一层一层往下搜 然后 搜到 得道者 就更新答案 AC代码 #include <c ...

  5. ubuntu16.04固定IP与设置DNS【转】

    本文转载自:http://www.jianshu.com/p/ea4bca38e5d7 学校几乎每次断电之后,宿舍的机器IP基本都会更改,即使可以通过图形界面去修改,但还是懒得去改.但是docker某 ...

  6. Cocos2d-x中锚点的介绍

    什么是锚点?  只需要记住一句话就可以,锚点就是你指定的那个坐标究竟是图像的哪个点,也就是你setPosition的坐标 eg: 新建工程:在HelloWorld中写上如下代码: CCSprite * ...

  7. PS 色调— —颜色梯度

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  8. ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)

    Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...

  9. ACM学习历程—HDU2222 Keywords Search(字典树)

    Keywords Search Description In the modern time, Search engine came into the life of everybody like G ...

  10. linux 安装SSH Server + FTP Server(openssh-server + vsftp)

    openssh-server (推荐. 一般ssh,ftp 都是单独的,但是这个包含2个) 默认ubuntu 已经安装了, ssh client ,ftp client dpkg -l | grep ...