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

分析

用邻接表法建树,dfs遍历,不难

#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int cnt=0,level=0,visited[100005]={0};
double p,r,maxprice=-1;
vector<int> G[100005];
void dfs(int s){
level++;
if(G[s].size()==0){
if(p*pow(1+0.01*r,level-1)>maxprice){
cnt=1;
maxprice=p*pow(1+0.01*r,level-1);
}else if(p*pow(1+0.01*r,level-1)==maxprice)
cnt++;
}
for(int i=0;i<G[s].size();i++)
dfs(G[s][i]);
level--;
}
int main(){
int n,t,s;
cin>>n>>p>>r;
for(int i=0;i<n;i++){
cin>>t;
if(t==-1) s=i;
else G[t].push_back(i);
}
dfs(s);
printf("%.2lf %d",maxprice,cnt);
return 0;
}

PAT 1090. Highest Price in Supply Chain的更多相关文章

  1. PAT 1090 Highest Price in Supply Chain[较简单]

    1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...

  2. 1090 Highest Price in Supply Chain——PAT甲级真题

    1090 Highest Price in Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), ...

  3. [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)

    1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...

  4. PAT 甲级 1090 Highest Price in Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...

  5. PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...

  6. 1090 Highest Price in Supply Chain (25 分)(模拟建树,找树的深度)牛客网过,pat没过

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  7. 1090. Highest Price in Supply Chain (25)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  8. 1090. Highest Price in Supply Chain (25) -计层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  9. 1090 Highest Price in Supply Chain (25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

随机推荐

  1. ADS-B显示终端6.8

    更新日志; 本次更新依旧主要注重是BUG修正. 1 改动鼠标移动时地图重绘的BUG 鼠标移动时地图即发生重绘,占用了CPU资源,修正后仅仅当鼠标点击选中对象或拖动对象时地图才会发生重绘.极大程度上节省 ...

  2. git出错调试

    https://stackoverflow.com/questions/6178401/how-can-i-debug-git-git-shell-related-problems git_trace ...

  3. 【BZOJ 1590】 Secret Message

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1590 [算法] 字典树 [代码] #include<bits/stdc++.h ...

  4. Cash Machine(多重背包)

    http://poj.org/problem?id=1276 #include <stdio.h> #include <string.h> ; #define Max(a,b) ...

  5. C Looooops(扩展欧几里得+模线性方程)

    http://poj.org/problem?id=2115 题意:给出A,B,C和k(k表示变量是在k位机下的无符号整数),判断循环次数,不能终止输出"FOREVER". 即转化 ...

  6. Python 32 通信循环 连接循环 粘包问题

    一:通信循环 二:连接循环 三:粘包问题

  7. Coursera公开课-Machine_learing:编程作业5

    Regularized Linear Regression and Bias/Variance 大多数时候,我们使用机器学习方法得到的结果都不是特别理想,常见 欠拟合 和 过拟合 问题.通过一些变量画 ...

  8. Application windows are expected to have a root view controller at the end of application launch

    今天把Xcode升级了,模拟器 用的12.1的系统,运行时发现项目总是崩溃,采用9.3系统的测试机发现错误日志如下: Application windows are expected to have ...

  9. 【Linux】创建逻辑卷管理(LVM)

    LVM是对磁盘进行分区管理的机制.LVM有很多优点:在线扩容,跨磁盘分区......,缺点:管理相对麻烦.创建LVM的过程如下: LVM是基于普通分区或者整块硬盘来进行的.我们首先把这些存储转换为PV ...

  10. 安装pywinauto的步骤

    team准备搞自动化测试(桌面WPF系统),这几天一直在找自动化测试工具.发现了pywinauto这款工具,许多网友反应很好用,于是下载下来试用.不得不说遇到的坑真不少,记录下来以备不时之需. 前段时 ...