紫书动规 例题9-12 UVA
来源:互联网 发布:软件项目部署方案 编辑:程序博客网 时间:2024/05/29 03:17
题目链接:
https://vjudge.net/problem/UVA-12186
题意:
题解:
d[u]:=让u给上级发信最少需要多少工人。假设u有k个节点,则至少c=(kT-1)/100+1个直接下属发信才行。 把所有子节点的d值从小到大排序,取前c个加起来就是当前的答案。
代码:
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define MS(a) memset(a,0,sizeof(a))#define MP make_pair#define PB push_backconst int INF = 0x3f3f3f3f;const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//////////////////////////////////////////////////////////////////////////const int maxn = 1e5+10;int n,T;vector<int> g[maxn];int dfs(int u){ int k = g[u].size(); if(k == 0) return 1; vector<int> d; for(int i=0; i<k; i++){ d.push_back(dfs(g[u][i])); } sort(d.begin(),d.end()); int c = (k*T-1)/100 + 1; int ans = 0; for(int i=0; i<c; i++) ans += d[i]; return ans;}int main(){ while(scanf("%d%d",&n,&T) && (n+T)){ for(int i=0; i<=n; i++) g[i].clear(); for(int i=1; i<=n; i++){ int u = read(); g[u].push_back(i); } cout << dfs(0) << endl; } return 0;}
0 0
- 紫书动规 例题9-12 UVA
- 紫书动规 例题9-9 UVA
- 紫书动规 例题9-1 UVA
- 紫书动规 例题9-2 UVA
- 紫书动规 例题9-3 UVA
- 紫书动规 例题9-4 UVA
- 紫书动规 例题9-5 UVA
- 紫书动规 例题9-6 UVA
- 紫书动规 例题9-7 UVA
- 紫书动规 例题9-8 UVA
- 紫书动规 例题9-10 UVA
- 紫书动规 例题9-13 UVA
- UVa #12186 Another Crisis (例题9-12)
- 例题9-1 UVa 1025
- 例题9-3 UVa 1347
- 例题 9-12 工人的请愿书 UVa 12186
- UVa #10003 Cutting Sticks (例题9-9)
- UVa #12627 Erratic Expansion (例题8-12)
- 构造方法
- ssh项目搭建
- JAVA中的字符串的indexOf函数 和substring
- Apriori算法
- java中String 类对象在克隆时候的特殊性
- 紫书动规 例题9-12 UVA
- 谷哥的小弟学后台(38)——SqlMapConfig.xml
- leetcode- Sum of Left Leaves
- Java中byte与(16进制)字符串的互相转换
- hibernate缓存机制详细分析 (转)
- 【集训队出题2011】大楼 题解
- 关于jsp乱码问题
- Cloud Computing(5)_Big Data Infrastructure
- 魔兽登陆页面