题意:某公司有1个老板和n(n<=105)个员工组成树状结构,除了老板之外每个员工都有唯一的直属上司。老板的编号为0,员工编号为1~n。无下属的员工(叶子)打算签署一项请愿书递给老板,但不能跨级递,只能递给直属上司。当一个中级员工(非叶子)的直属下属中不小于T%的人签字时,他也会签字并且递给他的直属上司。问:要让公司老板收到请愿书,至少需要多少个工人签字?

分析:

1、dfs(u)表示让u给上级发信最少需要多少个工人。

2、需要在u的孩子结点中选择不小于T%的人数,这些人所需的工人签字越少越好,所以需要排序。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1e5 + 10;
const int MAXT = 10000 + 10;
using namespace std;
vector<int> v[MAXN];
int N, T;
int dfs(int cur){
int len = v[cur].size();
if(!len) return 1;
vector<int> tmp;
for(int i = 0; i < len; ++i){
tmp.push_back(dfs(v[cur][i]));
}
sort(tmp.begin(), tmp.end());
int cnt = (int)ceil(len * (double)T / 100);
int ans = 0;
for(int i = 0; i < cnt; ++i){
ans += tmp[i];
}
return ans;
}
int main(){
while(scanf("%d%d", &N, &T) == 2){
if(!N && !T) return 0;
for(int i = 0; i < MAXN; ++i) v[i].clear();
for(int i = 1; i <= N; ++i){
int x;
scanf("%d", &x);
v[x].push_back(i);
}
printf("%d\n", dfs(0));
}
return 0;
}

  

最新文章

  1. 大端小端系统_union_栈的增长方向
  2. matlab练习程序(构造简单多边形)
  3. android 学习随笔十一(网络:HttpClient框架)
  4. SQL SERVER 2008函数大全(含例子)
  5. Jquery attr判断服务器单选按钮失败
  6. linq 和 , 并 , 差 ,交
  7. C# 每天温习一点(IEnumerable&lt;TSource&gt;)
  8. oracle删除表语句
  9. Oracle SQL tuning 步骤
  10. LSJ_NHibernate第三章 IDAL,DAL,BLL
  11. JavaScript修改表中的内容
  12. Android之旅十八 百度地图环境搭建
  13. SHDP--Working With HBase (二)之HBase JDBC驱动Phoenix与SpringJDBCTemplate的集成
  14. [置顶] 自己动手写Web容器之TomJetty之六:动态页面引入
  15. J2EE之验证码实现
  16. 程序媛也话Android 之 自定义控件(垂直方向滑动条)
  17. jst通用删除数组中重复的值和删除字符串中重复的字符
  18. Java WebService学习资料
  19. 修改Linux命令提示符
  20. 缓存设计(cache-design)

热门文章

  1. 三、多线程基础-自旋_AQS_多线程上下文
  2. [经验] 项目中 session 过期后弹出的登录窗口无法登录怎么办
  3. Python可视化 | Seaborn包—heatmap()
  4. 题解 UVA10298 【Power Strings】
  5. 2017 青岛现场赛 I The Squared Mosquito Coil
  6. 17 MySQL的小技巧
  7. Windows驱动开发-派遣函数格式
  8. py交易
  9. 运行jar包中的main方法
  10. 获取QQ状态接口开发示例