标签:
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product 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 distribute them in a price that is r% higher than P. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.
Now given a supply chain, you are supposed to tell the highest price we can expect from some retailers.
Input Specification:
Each input file contains 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 are numbered from 0 to N-1); P, the price 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, each number Si is the index of the supplier for the i-th member. Sroot for the root supplier is defined to be -1. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in 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 two numbers. It is guaranteed that the price will not exceed 1010.
Sample Input:9 1.80 1.00 1 5 4 4 -1 4 5 3 6Sample Output:
1.85 2
类似于1079题
1 #include <iostream> 2 #include <vector> 3 #include <bitset> 4 #include <cmath> 5 #include <iomanip> 6 7 using namespace std; 8 9 struct Node 10 { 11 vector<int> vec; 12 int level; 13 }; 14 15 Node distributor[100000]; 16 double p, r; 17 int maxLevel = 0; 18 int cnt = 0; 19 20 void SetLevel(int root) 21 { 22 if (distributor[root].vec.empty()) 23 { 24 if (distributor[root].level > maxLevel) 25 { 26 maxLevel = distributor[root].level; 27 cnt = 1; 28 } 29 else if (distributor[root].level == maxLevel) 30 cnt++; 31 } 32 for (int i = 0; i < distributor[root].vec.size(); i++) 33 { 34 int child = distributor[root].vec[i]; 35 distributor[child].level = distributor[root].level + 1; 36 SetLevel(child); 37 } 38 } 39 40 int main() 41 { 42 int n, root; 43 cin >> n >> p >> r; 44 for (int i = 0; i < n; i++) 45 { 46 int supplier; 47 cin >> supplier; 48 if (supplier == -1) 49 root = i; 50 else 51 distributor[supplier].vec.push_back(i); 52 } 53 distributor[root].level = 0; 54 SetLevel(root); 55 56 cout << fixed << setprecision(2) << p*pow(1 + r*1.0 / 100, maxLevel) << " " << cnt; 57 }
PAT 1090. Highest Price in Supply Chain (25)
标签:
原文地址:http://www.cnblogs.com/jackwang822/p/4737714.html