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' ...
随机推荐
- Java for LeetCode 126 Word Ladder II 【HARD】
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- 窥探 Swift 之别具一格的 Struct 和 Class
说到结构体和类,还是那句话,只要是接触过编程的小伙伴们对这两者并不陌生.但在Swift中的Struct和Class也有着令人眼前一亮的特性.Struct的功能变得更为强大,Class变的更为灵活.St ...
- spring cloud初识
spring cloud是spring中的一个快速开发框架.本实例采用spring+maven来配置一个简单的spring开发实例. 1.首先安装java和maven环境. ①.安装java,不做过多 ...
- Android Weekly Notes Issue #322
Android Weekly Issue #322 August 12th, 2018 Android Weekly Issue #322. 本期内容包括: 键盘的图像支持; 网络安全实现; Kotl ...
- 获取HDC的几种方法
当需要在显示器上(当然包括打印机等设备上)绘图时,或者写文字的时候,需要取得设备的上下文句柄,即HDC,本文以下都称为HDC.那么,有哪些办法取得HDC呢? 1 BeginPain()和EndPain ...
- UVA11330 Andy's Shoes —— 置换分解
题目链接:https://vjudge.net/problem/UVA-11330 题意: 给出n双鞋子,鞋子按左右左右地摆放,但“左右”是否为一对鞋子是不确定的.问:至少交换多少次鞋子,才能把每双鞋 ...
- 数据库,序列化数据为json字符串
create PROCEDURE [dbo].[usp_SerializeJSON] @ParameterSQL as varchar(max) AS BEGIN declare @SQL nvarc ...
- jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' of undefined
原因:datatable表格内容有操作列,而表头没有定义操作列 少写了一行:<th>操作</th>
- Spring MVC文件上传下载工具类
import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import ...
- (转)Linux内核本身和进程的区别 内核线程、用户进程、用户线程
转自:http://blog.csdn.net/adudurant/article/details/23135661 这个概念是很多人都混淆的了,我也是,刚开始无法理解OS时,把Linux内核也当做一 ...