PAT 1090. Highest Price in Supply Chain
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的更多相关文章
- PAT 1090 Highest Price in Supply Chain[较简单]
1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...
- 1090 Highest Price in Supply Chain——PAT甲级真题
1090 Highest Price in Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), ...
- [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...
- PAT 甲级 1090 Highest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...
- PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...
- 1090 Highest Price in Supply Chain (25 分)(模拟建树,找树的深度)牛客网过,pat没过
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 1090. Highest Price in Supply Chain (25)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- 1090 Highest Price in Supply Chain (25 分)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
随机推荐
- vbs use
VBScript中SendKeys的妙用 标签: vbscriptbasicmicrosoftinsertdeletestring 2011-05-26 15:29 1830人阅读 评论(0) 收藏 ...
- Android push推送消息到达成功率优化
Android push推送消息到达成功率优化 问题:server向client发送消息.未考虑client是否在线,这种消息到达率是非常低的. 第一次优化:使用server离线缓存数据,推断假设cl ...
- Linux Framebuffer 驱动框架之一概念介绍及LCD硬件原理【转】
本文转载自:http://blog.csdn.net/liuxd3000/article/details/17464779 一.基本概念 帧缓冲(Framebuffer)是Linux系统为显示设备提供 ...
- C# 如何调用EventLog
工作原理: 1.在没有指定logname,仅仅指定了source的时候. 1.1 source存在 在写eventlog的时候,首先去找source,如果找到的话,就往这个source所在的log里面 ...
- sublime -text 删除已安装插件
按ctr+shift +p然后输入remove 回车,再输入要删除的插件名
- 91. ExtJS获取父子、兄弟容器元素方法
转自:https://blog.csdn.net/u014745818/article/details/44957341 1 1.当前对象的父对象(上级对象) this.ownerCt: 2.当前对象 ...
- sql将一个表中的数据插入到另一个表中
sql将一个表中的数据插入到另一个表中 列名不一定要相同,只要你在HH中列出要插入列的列表跟select from mm表中的选择的列的列表一一对应就可以了,当然两边的数据类型应该是兼容的. ...
- bzoj2822[AHOI2012]树屋阶梯(卡特兰数)
2822: [AHOI2012]树屋阶梯 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 879 Solved: 513[Submit][Status] ...
- POJ 1523 Tarjan求割点
SPF Description Consider the two networks shown below. Assuming that data moves around these network ...
- E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)
Problem description Mr. Santa asks all the great programmers of the world to solve a trivial problem ...