标签:
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 6
Sample Output:
1.85 2
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <iostream> 4 #include <string.h> 5 #include <math.h> 6 #include <algorithm> 7 #include <string> 8 #include <stack> 9 #include <queue> 10 using namespace std; 11 const int maxn=100010; 12 int n; 13 double r,p,ans=0; 14 15 vector<int> child[maxn]; 16 17 //求最大深度 18 int maxdep=0,anscount=0; 19 void DFS(int root,int depth) 20 { 21 if(child[root].size()==0) 22 { 23 if(depth>maxdep){ 24 maxdep=depth; 25 anscount=1; 26 }else if(depth==maxdep) 27 { 28 anscount++; 29 }else{ 30 } 31 } 32 for(int i=0;i<child[root].size();i++) 33 { 34 DFS(child[root][i],depth+1); 35 } 36 } 37 int main(){ 38 39 scanf("%d %lf %lf",&n,&p,&r); 40 r=r/100; 41 int root; 42 for(int i=0;i<n;i++) 43 { 44 int tmp; 45 scanf("%d",&tmp); 46 if(tmp==-1) 47 { 48 root=i; 49 }else 50 { 51 child[tmp].push_back(i); 52 } 53 54 } 55 DFS(root,0); 56 printf("%.2f %d",p*pow(1+r,maxdep),anscount); 57 return 0; 58 }
A1090. Highest Price in Supply Chain (25)
标签:
原文地址:http://www.cnblogs.com/ligen/p/4320895.html