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=0,res=0;
    bool flag=0;//判断是否是叶子节点
    for(int i=head[now];i;i=e[i].pre){
        int to=e[i].to;
        tmp[++cnt]=dfs(to);
        flag=1;
    }
    if(!flag)return 1;
    sort(tmp+1,tmp+cnt+1);
    int limit=(cnt*t-1)/100+1;
    for(int i=1;i<=limit;i++)res+=tmp[i];
    return res;
}
int main(){
    //freopen("Cola.txt","r",stdin);
    while(1){
        scanf("%d%d",&n,&t);
        memset(e,0,sizeof(e));
        memset(head,0,sizeof(head));
        num=0;
        if(n==0&&t==0)return 0;
        int x;
        for(int i=1;i<=n;i++){
            scanf("%d",&x);
            Insert(x,i);
        }
        printf("%d\n",dfs(0));
    }
}
时间: 2024-08-10 00:26:45

uva12186 Another Crisis的相关文章

UVa12186:Another Crisis(树形DP)

一道简单的树形DP送给你. A couple of years ago, a new world wide crisis started, leaving many people with economical problems. Some workers of a particular company are trying to ask for an increase in their salaries. 数年以前,人们遭受了世界范围的经济危机.于是某司工人们要求涨薪.(我百度了一下,金融危机

UVA12186--- Another Crisis (树形dp)

Description Download as PDF A couple of years ago, a new world wide crisis started, leaving many people with economical problems. Some workers of a particular company are trying to ask for an increase in their salaries. The company has a strict hiera

HDU 3749 Financial Crisis

Financial Crisis 题意:给一个图,包含N ( 3 <= N <= 5000 )个点, M ( 0 <= M <= 10000 )条边 and Q ( 1 <= Q <= 1000 )次查询.查询:两个点是否是点-双连通: 点-双连通:两点至少存在两条"点不重复"的路径:简称双连通(biconnected); 思路:直接调用dfs求割点的算法,其实也是Tarjan发明的,就是在判断出一个割点之后,就把栈S中该双连通分量的所有点(就在栈顶

uva 12186 Another Crisis 树形dp

// uva 12186 Another Crisis 树形dp // // 对于一个节点u,有k个子节点,则至少有c = (k * T - 1) / 100 + 1才能 // 发信,即c / k >= T / 100,则 c 的值为 k * T /100,上取整变成上式 // 将所有的子节点d从小到大排序,取前c个就是d[u]的值 // 紫书上的一题,之前看了好久好久,觉得挺好的,然而一直没做,今天就来 // 体验体验,挺好的一题,注意一下,如果一个节点是叶节点,直接return 1就好 //

UVA 12186 Another Crisis

UVA 12186 Another Crisis:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=243&page=show_problem&problem=3338 题意:世界危机发生了,工人们请求加薪.一个老板和n个员工组成树状结构,每个员工都有自己的唯一上司,Boss的编号为0,员工1~n,工人们打算签署一个志愿书给老板,但无法跨级,当一个中级员工(非是工人的员

UVA 12186 Another Crisis(树形DP)

A couple of years ago, a new world wide crisis started, leaving many people with economical problems. Some workers of a particular company are trying to ask for an increase in their salaries. The company has a strict hierarchy, in which each employee

洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm(恶心的DP)

P2905 [USACO08OPEN]农场危机Crisis on the Farm 1605: [Usaco2008 Open]Crisis on the Farm 牧场危机 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < M < 1000)个高高的草垛. 作为出色的指挥家,约翰可以通过口哨指挥奶牛们移动.他的口哨有四个音,分别能使所有 的牛塔向东南

Crisis of HDU(母函数)

Crisis of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4258    Accepted Submission(s): 1197 Problem Description 话说上回讲到HDU大战东洋小苟,结果自然是中方大胜,这一战也使得海东集团在全球同行业中的地位更加巩固.随着集团的发展,很多创业时期的元老逐步功成身退,

dp uva12186树上的动态规划

http://vjudge.net/problem/UVA-12186 d(u)表示让u给上级发信最少需要多少工人 #include <bits/stdc++.h> using namespace std; const int maxn = 1e5+10; int N,T,f; vector<int> sons[maxn]; int dp(int u){ if(sons[u].empty()) return 1; int k = sons[u].size(); vector<