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 ...
随机推荐
- ubuntu压缩
.tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)-------------------------- ...
- Effective C++ Item 33 Avoid hiding inherited names
class Base { private: int x; public: ; virtual void mf2(); void mf3(); ... }; class Derived: public ...
- Html解析
相关解析组件: HtmlAgilityPack CsQuery Winista.Text.HtmlParser
- Python 入门(七)函数
什么是函数 我们知道圆的面积计算公式为: S = πr² 当我们知道半径r的值时,就可以根据公式计算出面积.假设我们需要计算3个不同大小的圆的面积: r1 = 12.34 r2 = 9.08 r3 = ...
- PHP学习记录数组中的数组的指针
unshift在数组头增加一个元素,push在数组尾增加一个元素,shift删除数组的第一个元素,pop删除数组的最后一个元素: <?php $item=array('苹果'); //在数组最前 ...
- php 关于日期的知识总结
1.UNIX时间戳 time() echo time(); 2.UNIX时间戳转换为日期用函数: date() 一般形式:date(); 即 echo date(date('Y-m-d H:i:s ...
- 关于Windows下的批处理如何模拟Sleep
好好的批处理,居然没有正式的Sleep可供调用.有时候,确实感到很无趣. 1. 方法1: ping 1.1.1.1来模拟 好不容易从stackoverflow上找到一个答案(称之为答案,是因为它被人标 ...
- split()有个坑
刚才在做DBMS课程设计的时候遇到了一个以前遇到过的问题不过这次我没有一眼认出来,想了好一会才想起来. 就是在用split()方法来分割路径名字符串的时候,比如 String path = “E:\s ...
- outline的兼容性及使用限制
outline 和 border的区别: outline不占据文档空间,border占据文档空间. outline无法单独设置上下左右,只要设置outline,必须所有的边都设置:border可以设置 ...
- 在linux下安装wordpress
win下的简直傻瓜式操作:xampp打包一键安装 linux下的考虑到一些权限问题 还是有点蛋疼的 现在把流程贴出来做下记录: linux下安装xampp和wordpress的流程 ×由于linux下 ...