[建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
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. 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
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; const int maxn=1e5+;
const int INF=1e9;
struct Node
{
int data;
vector<int> child;
}node[maxn]; int max_deep=;
int layer[maxn]={}; void dfs(int s,int &deep)
{
if(node[s].child.size()==)
{
layer[deep]+=;
max_deep=max_deep>deep?max_deep:deep;
return ;
}
for(int i=;i<node[s].child.size();i++)
{
int v=node[s].child[i];
deep+=;
dfs(v,deep);
deep-=;
}
} int main()
{
int n;
double p,r;
cin>>n>>p>>r;
int root;
for(int i=;i<n;i++)
{
int f;
////scanf("%d",&f);
cin>>f;
if(f==-)
{
root=i;
continue;
}
node[f].child.push_back(i); }
int deep=;
dfs(root,deep);
double sum=p;
int tmp=max_deep;
while(tmp>)
{
tmp--;
sum*=(+r/.);
}
printf("%.2lf %d\n",sum,layer[max_deep]);
}
[建树(非二叉树)] 1090. Highest Price in Supply Chain (25)的更多相关文章
- [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)
		
1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...
 - 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)
		
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
 - 1090 Highest Price in Supply Chain (25)(25 分)
		
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
 - PAT Advanced 1090  Highest Price in Supply Chain (25) [树的遍历]
		
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...
 - PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
		
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
 - 1090. Highest Price in Supply Chain (25)-dfs求层数
		
给出一棵树,在树根出货物的价格为p,然后每往下一层,价格增加r%,求所有叶子节点中的最高价格,以及该层叶子结点个数. #include <iostream> #include <cs ...
 - 【PAT甲级】1090 Highest Price in Supply Chain (25 分)
		
题意: 输入一个正整数N(<=1e5),和两个小数r和f,表示树的结点总数和商品的原价以及每向下一层价格升高的幅度.下一行输入N个结点的父结点,-1表示为根节点.输出最深的叶子结点处购买商品的价 ...
 - pat1090. Highest Price in Supply Chain (25)
		
1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...
 
随机推荐
- Scribe+HDFS日志收集系统安装方法
			
1.概述 Scribe是facebook开源的日志收集系统,可用于搜索引擎中进行大规模日志分析处理.其通常与Hadoop结合使用,scribe用于向HDFS中push日志,而Hadoop通过MapRe ...
 - WPF 自定义ComboBox样式,自定义多选控件
			
原文:WPF 自定义ComboBox样式,自定义多选控件 一.ComboBox基本样式 ComboBox有两种状态,可编辑和不可编辑状态.通过设置IsEditable属性可以切换控件状态. 先看基本样 ...
 - [并发并行]_[线程模型]_[Pthread线程使用模型之三 客户端/服务端模型(Client/Server]
			
Pthread线程使用模型之三 客户端/服务端模型(Client/Server) 场景 1.在客户端/服务端模型时,客户端向服务端请求一些数据集的操作. 服务端执行执行操作独立的(多进程或跨网络)– ...
 - CF 1114 C. Trailing Loves (or L'oeufs?)
			
C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...
 - 2_C语言中的数据类型 (二)进制
			
1.1 二进制数.位.字节与字 我们习惯于十进制的数:10,12等 一个位只能表示0,或者1两种状态,简称bit,一个位是一个bit 一个字节为8个二进制,称为8位,简称BYTE,8个比特 ...
 - AServer - 基于Asp.net core Kestrel的超迷你http服务器
			
AServer是基于ASP.NET Core Kestrel封装的一个超迷你http服务器.它可以集成进你的Core程序里,用来快速的响应Http请求,而不需要集成整个ASP.NET Core MVC ...
 - nGrinder性能测试平台的安装部署
			
1.从GitHub下载war包: https://github.com/naver/ngrinder/releases 2.把ngrinder-controller-3.4.2.war重命名为ngri ...
 - Jmeter接口测试(十)测试报告
			
这是jmeter接口测试系列的第十篇总结,也是最后一篇,之后会把接口集成的一些内容发一个系列,分享给大家,供大家一起学习进步. 批量执行完接口测试之后,我们需要查看测试报告,在之前单个接口调试我们是通 ...
 - spring boot 使用及最佳实践
			
第一部分,spring boot 文档 Spring boot的使用 使用maven进行构建 用户可以通过继承spring-boot-starter-parent来获取默认的依赖. l 默认java ...
 - python-分叉树枝
			
import turtle def draw_branch(length): #绘制右侧树枝 if length >5: if length == 10: turtle.pencolor('gr ...