zoukankan      html  css  js  c++  java
  • UVA12186 Another Crisis

    Another Crisis

     A couple of years ago, a new world wide crisis started, leaving many people with economical problems. Some workers of a particular company are trying to ask for an increase in their salaries. The company has a strict hierarchy, in which each employee has exactly one direct boss, with the exception of the owner of the company that has no boss. Employees that are not bosses of any other employee are called workers. The rest of the employees and the owner are called bosses. To ask for a salary increase, a worker should file a petition to his direct boss. Of course, each boss is encouraged to try to make their subordinates happy with their current income, making the company’s profit as high as possible. However, when at least T percent of its direct subordinates have filed a petition, that boss will be pressured and have no choice but to file a petition himself to his own direct boss. Each boss files at most 1 petition to his own direct boss, regardless on how many of his subordinates filed him a petition. A boss only accounts his direct subordinates (the ones that filed him a petition and the ones that didn’t) to calculate the pressure percentage. Note that a boss can have both workers and bosses as direct subordinates at the same time. Such a boss may receive petitions from both kinds of employees, and each direct subordinate, regardless of its kind, will be accounted as 1 when checking the pressure percentage. When a petition file gets all the way up to the owner of the company, all salaries are increased. The workers’ union is desperately trying to make that happen, so they need to convince many workers to file a petition to their direct boss. Given the company’s hierarchy and the parameter T, you have to find out the minimum number of workers that have to file a petition in order to make the owner receive a petition. Input There are several test cases. The input for each test case is given in exactly two lines. The first line contains two integers N and T (1 ≤ N ≤ 105 , 1 ≤ T ≤ 100), separated by a single space. N indicates the number of employees of the company (not counting the owner) and T is the parameter described above. Each of the employees is identified by an integer between 1 and N. The owner is identified by the number 0. The second line contains a list of integers separated by single spaces. The integer Bi , at position i on this list (starting from 1), indicates the identification of the direct boss of employee i (0 ≤ Bi ≤ i − 1). The last test case is followed by a line containing two zeros separated by a single space. Output For each test case output a single line containing a single integer with the minimum number of workers that need to file a petition in order to get the owner of the company to receive a petition. Sample Input 3 100 0 0 0 3 50 0 0 0 14 60 0 0 1 1 2 2 2 5 7 5 7 5 7 5 0 0 Sample Output 3 2 5

    【题解】

    dp[i]表示i这个点往上递需要多少工人签字

    转移即可

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 #include <vector>
     7 #include <cmath> 
     8 
     9 inline void read(int &x)
    10 {
    11     x = 0;char ch = getchar(), c = ch;
    12     while(ch < '0' || ch > '9')c = ch, ch = getchar();
    13     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
    14     if(c == '-')x = -x;
    15 }
    16 
    17 const int MAXN = 100000 + 10;
    18 
    19 struct Edge
    20 {
    21     int u,v,nxt;
    22     Edge(int _u, int _v, int _nxt){u = _u;v = _v;nxt = _nxt;}
    23     Edge(){}
    24 }edge[MAXN << 1];
    25 int head[MAXN], cnt;
    26 
    27 inline void insert(int a, int b)
    28 {
    29     edge[++cnt] = Edge(a,b,head[a]);
    30     head[a] = cnt;
    31 }
    32 
    33 int n,t,dp[MAXN];
    34 
    35 void DP(int u, int fa)
    36 {
    37     std::vector<int> p; 
    38     for(register int pos = head[u];pos;pos = edge[pos].nxt)
    39     {
    40         int v = edge[pos].v;
    41         if(fa == v)continue;
    42         DP(v, u);
    43         p.push_back(dp[v]); 
    44     }
    45     if(!p.size())
    46     {
    47         dp[u] = 1;
    48         return;
    49     }
    50     sort(p.begin(), p.end());
    51     dp[u] = 0;
    52     int ma = (p.size() * t - 1) / 100 + 1;
    53     for(register int i = 0;i < ma;++ i)
    54         dp[u] += p[i];
    55 }
    56 
    57 int main()
    58 {
    59     while(scanf("%d %d", &n, &t) && n + t)
    60     {
    61         memset(head, 0, sizeof(head));
    62         cnt = 0;
    63         int tmp;
    64         for(register int i = 1;i <= n;++ i)
    65         {
    66             read(tmp);
    67             if(tmp == 0) tmp = n + 1;
    68             insert(tmp, i);
    69             insert(i, tmp);
    70         }
    71         DP(n + 1, 0);
    72         printf("%d
    ", dp[n + 1]);
    73     }
    74     return 0;
    75 } 
    UVA12186
  • 相关阅读:
    201202
    Android牟利之道(一)界面嵌入有米广告
    SoketException log
    ERROR: 9patch image about.9.png malformed.
    Conversion to Dalvik format failed with error 1
    absolute绝对定位(相对于整个html流)以及不为人知的(fixed)绝对定位(fixed相对于浏览器窗口=不动的div)
    about getElementsByTagName()的那点事
    js 不用onload的loding
    absolute fixed效果 复制网页打开就是代码 http://www.cnblogs.com/0banana0/archive/2011/05/25/2056643.html
    关于datetime的那点事
  • 原文地址:https://www.cnblogs.com/huibixiaoxing/p/7710065.html
Copyright © 2011-2022 走看看