zoukankan      html  css  js  c++  java
  • 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 Submission(s): 306    Accepted Submission(s): 217


    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
     
    Source
     
    解题:一顿乱搞
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 100010;
     4 struct arc {
     5     int to,next;
     6     arc(int x = 0,int y = -1) {
     7         to = x;
     8         next = y;
     9     }
    10 } e[maxn];
    11 int head[maxn],tot;
    12 void add(int u,int v) {
    13     e[tot] = arc(v,head[u]);
    14     head[u] = tot++;
    15     e[tot] = arc(u,head[v]);
    16     head[v] = tot++;
    17 }
    18 int ind[maxn],cnt[maxn],ret,n,k;
    19 void dfs(int u,int fa) {
    20     cnt[u] = 1;
    21     for(int i = head[u]; ~i; i = e[i].next) {
    22         if(e[i].to == fa) continue;
    23         dfs(e[i].to,u);
    24         cnt[u] += cnt[e[i].to];
    25     }
    26     if(k + 1 == cnt[u]) ++ret;
    27 }
    28 int main() {
    29     int u,v;
    30     while(~scanf("%d%d",&n,&k)) {
    31         memset(head,-1,sizeof head);
    32         memset(ind,0,sizeof ind);
    33         ret = tot = 0;
    34         for(int i = 1; i < n; ++i) {
    35             scanf("%d%d",&u,&v);
    36             add(u,v);
    37             ++ind[v];
    38         }
    39         for(int i = 1; i <= n; ++i)
    40             if(!ind[i]) {
    41                 dfs(i,-1);
    42                 break;
    43             }
    44         printf("%d
    ",ret);
    45     }
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    利用读写锁实现缓存系统
    POJ 1338 Ugly Numbers
    copy算法
    它们的定义iOS双击Home截图按键开关
    以正能量的点!!!
    该公路项目
    ArcSDE当关系查询ArcMap与REST查询结果不一致问题的解决
    【OpenCV新手教程第14】OpenCVHough变换:霍夫变换线,霍夫变换圆汇编
    为了树莓派IIraspberrypi安装emacs+ecb+cedet+session+color-theme+cscope+linum
    事件总线帧---Otto
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4684353.html
Copyright © 2011-2022 走看看