hdu 5326
Work
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 618 Accepted Submission(s): 412
Problem Description
It’s an interesting experience to move from ICPC to work, end my college life and start a brand new journey in company.
As is known to all, every stuff in a company has a title, everyone except the boss has a direct leader, and all the relationship forms a tree. If A’s title is higher than B(A is the direct or indirect leader of B), we call it A manages B.
Now, give you the relation of a company, can you calculate how many people manage k people.
Input
There are multiple test cases.
Each test case begins with two integers n and k, n indicates the number of stuff of the company.
Each of the following n-1 lines has two integers A and B, means A is the direct leader of B.
1 <= n <= 100 , 0 <= k < n
1 <= A, B <= n
Output
For each test case, output the answer as described above.
Sample Input
7 2
1 2
1 3
2 4
2 5
3 6
3 7
Sample Output
2
//这题是要求管理了m个人的有多少个
//利用pre[]数组 记录每一个b的pre[b]为a; 接着从b到根的中的人掌控的个数+1 比如
3 2 1 2 2 3 pre[2]=1; c[1]++ pre[3]=2; c[2]++-> pre[2]=1 c[1]++; 所以掌握个数为2的有一个c[1]
#include <stdio.h>
#include <string.h>
int pre[110];
int c[110]; int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(c,0,sizeof(c));
for(int i=0;i<=n;i++)
pre[i]=i;
int a,b;
for(int i=0;i<n-1;i++)
{
scanf("%d%d",&a,&b);
pre[b]=a;
while(pre[b]!=b) //从b到根 每一个上级掌控人数加1。
{
b=pre[b];
c[b]++;
}
}
int cnt=0;
for(int i=1;i<=n;i++)
{
if(c[i]==m)
cnt++;
}
printf("%d\n",cnt);
}
return 0;
}
hdu 5326的更多相关文章
- HDU 5326(2015多校3)-Work(dfs)
题目地址:pid=5326">HDU 5326 题意:给一张有向图n个点.n - 1(....输入n-1)条边. A指向B代表A管理B.然后能够间接管理,比方A管理B,B管理C.则A管 ...
- hdu 5326 Work
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Description It’s an interesting experience ...
- hdu 5326(基础题) work
http://acm.hdu.edu.cn/showproblem.php?pid=5326 一道水题,题目大意是在公司里,给出n个员工和目标人数m,然后下面的n-1行是表示员工a管理b,问在这些员工 ...
- hdu 5326 Work(杭电多校赛第三场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 5326 work (回溯,树)
题意:给一棵树,每个结点的子树下的结点都是它的统治对象,问有多少个统治对象数目为k的结点? 思路:每个结点都设一个cnt来记数,只要将每个结点往上回溯,直到树根,经过的每个结点都将计数器加1.最后再扫 ...
- ACM学习历程—HDU 5326 Work(树形递推)
Problem Description It’s an interesting experience to move from ICPC to work, end my college life an ...
- 2015 Multi-University Training Contest 3 hdu 5326 Work
Work Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏
K - Work Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU OJ 5326 Work( 2015多校联合训练第3场) 并查集
题目连接:戳ME #include <iostream> #include <cstdio> #include <cstring> using namespace ...
随机推荐
- [SQL]197. Rising Temperature
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...
- Iphone6手机不同浏览器页面尺寸设计
做移动端html5页面适配,通常要考虑很多种情况. 对于同一部手机,通常要考虑如下3点: 1. 在手机普通浏览器中打开,比如Safari浏览器,UC浏览器,QQ浏览器,360浏览器,谷歌浏览器. 2. ...
- BZOJ.2460.[BeiJing2011]元素(线性基 贪心)
题目链接 线性基:https://blog.csdn.net/qq_36056315/article/details/79819714. \(Description\) 求一组矿石,满足其下标异或和不 ...
- Mysql的学习随笔day1
关于mysql的基本语句 ps:[]是缺省 创建:CREATE DATABASE db.name CREATE TABLE name(列名,类型,[NULL])NOT NULL是不需要为空,NOT ...
- lor框架代码分析
属性 lor: version router route request response fn app create_app Router Route Request Response 属性 lor ...
- Codeforces Round #352 (Div. 1) B. Robin Hood 二分
B. Robin Hood 题目连接: http://www.codeforces.com/contest/671/problem/B Description We all know the impr ...
- How to exit the entire application from a Python thread?
If all your threads except the main ones are daemons, the best approach is generally thread.interrup ...
- HttpPost+json请求---服务器中文乱码及其他
好凌乱的题目,只是一些功能点的总结咯. 首先构造一个json对象用于存放数据,如果光加上header为utf-8就能解决中文就大错特错了... json对象可以put变量,也可以put对象.取的时候o ...
- 在Powerdesigner中创建概念数据模型
点击菜单“File”---->“New Model” 点击[OK]按钮后,将进入如下的画面 系统将出现一个工具栏如下,用于在设计面板中设计模型
- Linux系统不可不知的命令:sudo
转自:http://www.embeddedlinux.org.cn/html/xinshourumen/201308/05-2608.html sudo是个统管一切的命令.它的字面意思是代表“超级用 ...