K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
System Crawler (2015-07-28)
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
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
Sample Input
7 2
1 2
1 3
2 4
2 5
3 6
3 7
Sample Output
2题意就是,有n个人,判断有几个人领导的人数是k,输入两个数,前面的领导后面的;#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm> using namespace std; const int MAX = 110; int Map[MAX][MAX]; int Dp[MAX]; int n,k; int DFS(int s)//DFS搜索每个人所领导的人数;
{
if(Dp[s])
{
return Dp[s];
}
int sum=0;
for(int i=1;i<=n;i++)
{
if(Map[s][i])
{
sum++;
sum+=DFS(i);
}
}
Dp[s]=sum;
return Dp[s];
} int main()
{
int a,b;
while(~scanf("%d %d",&n,&k))
{
memset(Map,0,sizeof(Map));
memset(Dp,0,sizeof(Dp));
for(int i=1;i<n;i++)
{
scanf("%d %d",&a,&b);
Map[a][b]=1;
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(DFS(i)==k)
{
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏的更多相关文章
- 欧拉通路-Play on Words 分类: POJ 图论 2015-08-06 19:13 4人阅读 评论(0) 收藏
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10620 Accepted: 3602 Descri ...
- Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 二分图匹配 分类: ACM TYPE 2014-10-01 19:57 94人阅读 评论(0) 收藏
#include<cstdio> #include<cstring> using namespace std; bool map[505][505]; int n, k; bo ...
- Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏
Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...
- Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...
- Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...
- 迷之节约 分类: sdutOJ 最小生成树 2015-06-24 19:10 10人阅读 评论(0) 收藏
迷之节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 FF超级有钱,最近又买了n个(1 <= n <= 300)小岛,为 ...
- 菊花加载第三方--MBprogressHUD 分类: ios技术 2015-02-05 19:21 120人阅读 评论(0) 收藏
上次说到了网络请求AFN,那么我们在网络请求的时候,等待期间,为了让用户不认为是卡死或程序出错,一般都会放一个菊花加载,系统有一个菊花加载类叫UIProgressHUD.但是我今天要说的是一个替代它的 ...
- 浅谈IOS8之size class 分类: ios技术 2015-02-05 19:06 62人阅读 评论(0) 收藏
文章目录 1. 简介 2. 实验 3. 实战 3.1. 修改 Constraints 3.2. 安装和卸载 Constraints 3.3. 安装和卸载 View 3.4. 其他 4. 后话 以前和安 ...
随机推荐
- Azure 负载均衡和可用性集
首先要2台以上的虚拟机,一开始我找了好久都没找到如何在一个云服务里添加多个虚拟机. 因为我使用的是快速创建,快速创建的界面是要新建一个云服务的,如果你输入现有的云服务名字,它会提示你重名了. 你要用[ ...
- Moment.js学习(一)源代码
本篇主要是学习Moment.js.类库源代码如下: 2.4版本. //! moment.js //! version : 2.4.0 //! authors : Tim Wood, Iskren Ch ...
- Beyond Compare
Beyond Compare是一个比较文件和文件夹的工具. 它可以帮助你找到并协调源代码.文件夹.图像和数据间的差异,即使包括zip文档中或者FTP站点上的文件. 另外它还可以同步化文件夹并验证不 ...
- linux 内核模块ko入门
http://blog.csdn.net/elfylin/article/details/5908265
- 实验十五_安装新的int 9中断例程
安装一个新的int 9中断例程,功能:在DOS下,按下“A”键后,除非不在松开, 如果松开,就显示满屏幕的“A”:其他的键照常处理. 提示:按下一个键时产生的扫描码称为通码,松开一个键产生的扫描 ...
- Lintcode: Remove Node in Binary Search Tree
iven a root of Binary Search Tree with unique value for each node. Remove the node with given value. ...
- struts2 radio标签 单选按钮
<s:radio name="sex" label="性别" list="#{'男':'男','女':'女'}" value=&quo ...
- [转]jQueryEasyUI Messager基本使用
一.jQueryEasyUI下载地址 http://www.jeasyui.com/ 二.jQueryEasyUI Messager基本使用 1.$.messager.alert(title, msg ...
- 浅谈thinkphp中将字符串转换成json数组的方法
这是一部分代码: $client = M("Client");$data = $client->where('user_id ='.$user_id)->select( ...
- android Activity的启动模式与flag的见解
最近做一个安卓项目,想要实现的效果就是:当打开一个按钮的时候,启动了一个A功能,当用户返回到桌面再继续进去的时候,不过之前在哪个Activity,都会先跳转到A功能的那个界面,当用户点击返回的时候,再 ...