UVA 12186 another crisis:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&category= 243&page=show_problem&problem=3338
Test instructions: The world crisis has happened and workers are asking for a raise. A boss and N employees form a tree structure, each employee has their own sole boss, the boss number is 0, the employee 1~n, the workers are going to sign a form page to the boss, but can not cross the level, when an intermediate employee (not the worker's employees) directly subordinate of the person not less than t% signature, He would also sign and hand it to his immediate boss, asking how many workers the boss would need to sign to get the petition.
Algorithm analysis: Set d[u] means let u to the superior to send a letter at least how many workers. Suppose you have a K child node, you need at least c= (kT-1) 100+1 Direct subordinate letter. The D value of all child nodes is sorted from small to large, and the first C is added up. Complexity of Time: O (NLOGN)
Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <vector> using namespace std ; #define MAXN 100005vector<int>sons[maxn];int n,t;int dp (int u) {if (Sons[u].empty ()) Return 1;int k=sons[u].size ( ); vector<int>d;for (int i=0;i<k;i++) D.push_back (DP (sons[u][i)); Sort (D.begin (), D.end ()); int c= (K*T-1)/ 100+1;int ans=0;for (int i=0;i<c;i++) Ans+=d[i];return ans;} int main () {while (~scanf ("%d%d", &n,&t) && (n| | T)) {for (int i=0;i<=n;i++) sons[i].clear (); int temp;for (int i=1;i<=n;i++) {//Start scanf from the first child node ("%d", &temp); Sons[temp].push_back (i);} printf ("%d\n", DP (0));} return 0;}
UVA 12186 another Crisis