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 ...
随机推荐
- 使用tensorflow深度学习识别验证码
除了传统的PIL包处理图片,然后用pytessert+OCR识别意外,还可以使用tessorflow训练来识别验证码. 此篇代码大部分是转载的,只改了很少地方. 代码是运行在linux环境,tesso ...
- EF的代码优先设计
CodeFirst 用中文说是代码优先,此技术可以让我们先写代码,然后由Entity Framework根据我们的代码建立数据库 接下来用学生这个例子来演示,有学生表,课程表,和成绩表三张表 首先是M ...
- python2.0 s12 day3
s12 day3 视频每节的内容 03 python s12 day3 本节内容概要 第三天的主要内容 上节没讲完的: 6.集合 7.collections 1)计数器 2)有序字典 3)默认字典 4 ...
- raw_input()
raw_input() 用于接收标准输入,并把标准输入当成字符串类型来处理,只能在 Python2 中使用,Python3 中没有这个函数 #!/usr/bin/env python #-*- cod ...
- git 提交代码出现git Permission to Xx denied to Xx 错误
http://blog.csdn.net/chen_xi_hao/article/details/71172279
- case when 的实战应用(分别取图片展示问题)
SELECT lg.product_id, lg.goods_id, lg.goods_no, lg.product_price, lg.product_stock, lg.limit_amount, ...
- Sphinx以及coreseek的安装及使用 .No1
检索结构php -> sphinx -> mysql非结构化数据又叫全文数据,非固定长度字段例如文章标题搜索这类适用sphinx 全文数据搜索:顺序扫描 : 如like查找索引扫描 : 把 ...
- javascript:;禁用a标签默认功能的缺点。
在使用a标签做切换tab或者其他功能时,经常使用javascript:;来作为a标签的href来使用. 缺点: 1.在js尚未加载的情况下,点击该a标签会弹出新窗口. 2.会使gif动画失效(没经历过 ...
- IIS的安装和配置
一.首先是安装IIS.打开控制面板,找到“程序与功能” 二. “打开或关闭Windows功能”, 安装 “Internet 信息服务” 三. 安装完后回控制面板里面,找到“管理工具” 四. 双击“In ...
- 1.border-image
1.设置在元素围绕的border的图片,用图片代替边框 语法: broder-image-source:图片 border-image-slice:切下的区域,数字|百分比(相对于图像的高度和宽度) ...