UVA 12186 another Crisis

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.