1090 Highest Price in Supply Chain (25)(25 分)
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 (<=10^5^), 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 S~i~ is the index of the supplier for the i-th member. S~root~ 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 10^10^.
Sample Input:
9 1.80 1.00
1 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = ;
vector<int> child[maxn];
int n,maxDepth = ,num = ;
double p,r; void DFS(int index,int depth){
if(child[index].size() == ){
if(depth > maxDepth){
maxDepth = depth;
num = ;
}else if(depth == maxDepth){
num++;
}
return;
}
for(int i = ; i < child[index].size(); i++){
DFS(child[index][i],depth+);
}
} int main(){
scanf("%d%lf%lf",&n,&p,&r);
int father,root;
r /= ;
for(int i = ; i < n; i++){
scanf("%d",&father);
if(father != -){
child[father].push_back(i);
}
else{
root = i;
}
}
DFS(root,);
printf("%.2f %d\n",p*pow(+r,maxDepth),num);
return ;
}
最新文章
- PS技巧:如何优雅的抠公章?
- 使用Githua管理代码
- Windows Phone App的dump文件实例分析- System.ExecutionEngineException
- WIN7下更改TFS连接用户的方法
- Android 中获取 debug 测试 SHA1 和 release SHA1 证书指纹数据的方法
- POJ2104 K-th Number 划分树 模板题啊
- Java 编程的动态性,第 7 部分: 用 BCEL 设计字节码--转载
- HTML - Textarea - 空格的问题解决方式
- AndroidGradle--瘦身apk(转发)
- [Mysql]备份同库中一张表的历史记录 insert into ..select
- Java生成名片式的二维码源码分享
- Day 1 下午
- linux 工具
- H5取经之路——添加hover实现特定效果
- WIN8 Metro UI 风格下的微软报表开发与设计 Metro UI SSRS - BIWORK
- JavaScript substr() 字符串截取函数使用详解
- beego 初体验 - orm
- jvm(1)类加载(一)(加载过程,双亲加载)
- PHP扩展模块redis安装
- 20172329 2018-2019《Java软件结构与数据结构》第一周学习总结