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 ...
随机推荐
- CSS使用经验总结
清除图片下方出现几像素的空白间隙 方法1: img{display:block;} 方法2: img{vertical-align:top;} 除了top值,还可以设置为text-top | midd ...
- WPF 跟踪命令和撤销命令(复原)
WPF 命令模型缺少一个特性是复原命令.尽管提供了一个 ApplicationCommands.Undo 命令,但是该命令通常被用于编辑控件(如 TextBox 控件),以维护它们自己的 Undo 历 ...
- Effective C++ Item 18 Make interfaces easy to use correctly and hard to use incorrectly
1. A good API will provide easy to use interfaces but also provide hard to miss-use interfaces. Usua ...
- swift开发之 -- 自动轮播图(UIScrollView+UIPageControl+Timer)
比较简单,原理就不说了,这里只做记录: 代码如下: 1,准备 var pageControl:UIPageControl? var myscrollView:UIScrollView? var myT ...
- Python 高斯坐标转经纬度算法
# 高斯坐标转经纬度算法# B=大地坐标X# C=大地坐标Y# IsSix=6度带或3度带def GetLatLon2(B, C,IsSix): #带号 D = math.trunc(C / 1000 ...
- shell基础篇(一)从hello world开始
前记:这里是我做的shell笔记:接下来会提供一系列. Shell是一种脚本语言,那么,就必须有解释器来执行这些脚本.Unix/Linux上常见的Shell脚本解释器有bash.sh.csh.ksh等 ...
- phpsession配置
1. 介绍 1.1 作用: 主要用于服务器端的会话保持. 1.2 结构: Session分以下几部分: 1)Session id 用户Session的唯一标识(随机生成,具有唯一性,随机性) 2)Se ...
- JS 保存表单默认值 为空时自动填充默认值
var inputArray = document.getElementsByTagName("input"); var strArray = []; ; i < input ...
- SSH配置优化和慢的解决方法
author: headsen chen date: 2018-08-18 00:28:37 ssh配置优化 vim /etc/ssh/sshd_config 1,修改root端口 2,不允许ro ...
- jhipser微服务架构介绍
内容提要 本文涉及以下内容: 微服务架构介绍 spring cloud介绍 jhipster架构介绍 微服务架构介绍 微服务概念 微服务和SOA很相似,都是按照业务功能把系统拆分成一个一个的服务.比如 ...