码迷,mamicode.com
首页 > 其他好文 > 详细

hdu5326(多校)

时间:2015-08-27 13:34:53      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326


Work

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1147 Accepted Submission(s): 695


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

Author
ZSTU

Source

直接暴力就OK

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;

int s[105][105],f[105];
int n,k;
int cnt,ans;

void solve(int m)
{
    int t = m;
    if (t>=n||f[t]==0)
        return ;
    for (int i=1; i<=n; i++)
    {
        if (s[t][i])
        {
            cnt+=f[i];
            solve(i);
        }
    }
}

int  main()
{
    int a,b;
    while (scanf ("%d%d",&n,&k)==2)
    {
        memset(s, 0, sizeof(s));
        memset(f, 0, sizeof(f));
        for (int j=1; j<n; j++)
        {
            scanf ("%d%d",&a,&b);
            s[a][b] = 1;
            f[a]++;
        }
        cnt=0,ans=0;
        for (int i=1; i<=n; i++)
        {
            cnt = f[i];
            solve(i);
            if (cnt == k)
                ans++;
        }
        printf ("%d\n",ans);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu5326(多校)

标签:

原文地址:http://blog.csdn.net/d_x_d/article/details/48024159

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!