PAT 1090. Highest price in supply Chain (25)

Source: Internet
Author: User

1090. Highest price in supply Chain (25)

A supply chain is a network of retailers (retailer), distributors (dealer), and suppliers (supplier)--everyone involved in moving a produ CT from supplier to customer.

Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or Distribu Te them in a price, is r% higher than P. It is assumed this member in the supply chain have exactly one supplier except the root supplier, and there is no supp Ly cycle.

Now given a supply chain and you is supposed to tell the highest price we can expect from some retailers.

Input Specification:

Each input file contains the one test case. For each case, the first line contains three positive numbers:n (<=105), the total number of the "members" in the supply Chain (and hence they is numbered from 0 to N-1); P, the price of given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers and each number Si are the index of the supplier for the i-th member. Sroot for the root supplier are defined to be-1. All the numbers in a line is separated by a space.

Output Specification:

For all test case, print on one line the highest price we can expect from some retailers, accurate up to 2 decimal places , and the number of retailers that sell at the highest price. There must be one space between the numbers. It is guaranteed, the price would not exceed 1010.

Sample Input:
9 1.80 1.001 5 4 4-1 4 5 3 6
Sample Output:
1.85 2

Similar to 1079 questions
1#include <iostream>2#include <vector>3#include <bitset>4#include <cmath>5#include <iomanip>6 7 using namespacestd;8 9 structNodeTen { Onevector<int>Vec; A     intLevel ; - }; -  theNode distributor[100000]; - Doublep, R; - intMaxlevel =0; - intCNT =0; +  - voidSetLevel (introot) + { A     if(Distributor[root].vec.empty ()) at     { -         if(Distributor[root].level >maxlevel) -         { -Maxlevel =Distributor[root].level; -CNT =1; -         } in         Else if(Distributor[root].level = =maxlevel) -cnt++; to     } +      for(inti =0; I < distributor[root].vec.size (); i++) -     { the         intChild =Distributor[root].vec[i]; *Distributor[child].level = Distributor[root].level +1; $ SetLevel (child);Panax Notoginseng     } - } the  + intMain () A { the     intn, Root; +CIN >> n >> P >>R; -      for(inti =0; I < n; i++) $     { $         intsupplier; -CIN >>supplier; -         if(Supplier = =-1) theRoot =i; -         ElseWuyi Distributor[supplier].vec.push_back (i); the     }     -Distributor[root].level =0; Wu SetLevel (root); -  Aboutcout <<fixed<< Setprecision (2) << P*pow (1+ r*1.0/ -, Maxlevel) <<" "<<CNT; $}

PAT 1090. Highest price in supply Chain (25)

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.