PAT 1090 Highest Price in Supply Chain[较简单]
1090 Highest Price in Supply Chain(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 (≤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. Srootfor 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
题目大意:也是一个销售链,给出一个树结构,求数的高度,并且在最高的叶节点有几个。
//这个和1079是类似的,都是使用dfs吧!传参进去一定要有level咯,记住maxLevel和每个叶节点的层数即可。
#include <iostream>
#include<stdio.h>
#include<cmath>
#include<vector>
using namespace std;
double p,r;
vector<int> tree[];
int book[];
int maxL=;
void dfs(int index,int level){
if(tree[index].size()==){
book[index]=level;
if(level>maxL)
maxL=level;
return ;
}
for(int i=;i<tree[index].size();i++)
dfs(tree[index][i],level+);
} int main() {
int n;
scanf("%d %lf %lf",&n,&p,&r);
int temp,root=-;
for(int i=;i<n;i++){
scanf("%d",&temp);
if(temp!=-){
tree[temp].push_back(i);
}
else root=i;
}
dfs(root,);
int ct=;
for(int i=;i<n;i++){
if(book[i]==maxL)
ct++;
}
printf("%.2f %d",p*pow(+r/,maxL),ct);
return ;
}
//一次通过,简直非常开心了!我应该把关于树的深度遍历,高度,这些东西都掌握了。非常开心。
1.树的dfs都是有结构的,非常简单。
2.需要记录叶节点的高度。
PAT 1090 Highest Price in Supply Chain[较简单]的更多相关文章
- PAT 1090. Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 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 ...
随机推荐
- JavaScript------去掉Array中重复值
转载: http://blog.csdn.net/teresa502/article/details/7926796 代码: // 删除数组中重复数据 function removeDuplElem( ...
- Python 爬虫知识点 - 淘宝商品检索结果抓包分析
一.抓包基础 在淘宝上搜索“Python机器学习”之后,试图抓取书名.作者.图片.价格.地址.出版社.书店等信息,查看源码发现html-body中没有这些信息,分析脚本发现,数据存储在了g_page_ ...
- VS添加命令行参数main(int argc, char** argv)
- (转)关于android设备管理器的一些分析
转自http://bbs.pediy.com/showthread.php?t=183692 想必很多人都知道轰动一时android木马OBAD,该木马利用android设备管理器的漏洞,当用户激活设 ...
- MQTT的学习研究(三)moquette-mqtt 的使用之mqtt服务发布主题信息
接着上一篇的moquette-mqtt 的使用之broker启动之后,我们需要启动moquette-mqtt 的服务端发布消息. 在moquette-mqtt 的mqtt-client中三种方式实现发 ...
- MyBatis——Java API
Java API 既然你已经知道如何配置 MyBatis 和创建映射文件,你就已经准备好来提升技能了. MyBatis 的 Java API 就是你收获你所做的努力的地方.正如你即将看到的,和 JDB ...
- vue中npm install 报错之一
报错原因: 这是因为文件phantomjs-2.1.1-windows.zip过大,网络不好,容易下载失败 PhantomJS not found on PATH 解决方案一: 选择用cnpm ins ...
- js嵌套轮播图
$(function(){ var navLi = $(".top_nav").find("li"), conDiv = $(".top_con&qu ...
- 【BZOJ3362-3365】USACO水题四连A
[BZOJ3362][Usaco2004 Feb]Navigation Nightmare 导航噩梦 Description 农夫约翰有N(2≤N≤40000)个农场,标号1到N,M(2≤M≤ ...
- Unity3D笔记五 快捷键
一.近距离查看游戏对象 在Hierarchy视图中选择游戏对象,然后在Scene视图中按快捷键“F”来近距离查看该游戏对象. 二.游戏对象不在主摄像头中? Hierarchy中双击选择需要显示的游戏对 ...