[建树(非二叉树)] 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 ...
随机推荐
- 大数据入门:Hadoop安装、环境配置及检测
目录 1.导包Hadoop包 2.配置环境变量 3.把winutil包拷贝到Hadoop bin目录下 4.把Hadoop.dll放到system32下 5.检测Hadoop是否正常安装 5.1在ma ...
- R语言学习笔记(十九):字符串处理中预定义字符组(表格介绍)
R中预定义的字符组 代码 含义说明 [:digit:]或\\d 数字; [0-9] [^[:digit:]]或\\D 非数字; 等价于[^0-9] [:lower:] 小写字母; [a-z] [:up ...
- [转]Kafka 设计与原理详解
一.Kafka简介 本文综合了我之前写的kafka相关文章,可作为一个全面了解学习kafka的培训学习资料. 1 2 1 2 转载请注明出处 : 本文链接 1.1 背景历史 当今社会各种应用系统诸如商 ...
- 20155318 2016-2017-2 《Java程序设计》第七学习总结
20155318 2016-2017-2 <Java程序设计>第七学习总结 教材学习内容总结 学习目标 了解Lambda语法 了解方法引用 了解Fucntional与Stream API ...
- Openstack入门篇(十一)之neutron服务(控制节点)的部署与测试
1.Neutron的介绍 Neutron 为整个 OpenStack 环境提供网络支持,包括二层交换,三层路由,负载均衡,防火墙和 *** 等.Neutron 提供了一个灵活的框架,通过配置,无论是开 ...
- javaweb学习3——验证码
声明:本文只是自学过程中,记录自己不会的知识点的摘要,如果想详细学习JavaWeb,请到孤傲苍狼博客学习,JavaWeb学习点此跳转 本文链接:https://www.cnblogs.com/xdp- ...
- Linux入门基础(七):Linux软件管理基础
源代码形式 绝大多数开源软件都是直接以源代码形式发布 源代码一般会被打包成tar.gz的归档压缩文件 程序源代码需要编译成为二进制形式之后才能够运行 源代码基本编译流程 : ./configure 检 ...
- 学习java常见dos命令
在java基础学习阶段时一般会在dos命令行下操作文件,这里列出一些常用命令. 打开DOS控制台的方式 按win+r 再输入 cmd 然后回车. 常用DOS命令 d: 回车 盘符切换 (盘符加冒号) ...
- opengl摄像机
摄像机/观察空间 当我们讨论摄像机/观察空间(Camera/View Space)的时候,是在讨论以摄像机的视角作为场景原点时场景中所有的顶点坐标:观察矩阵把所有的世界坐标变换为相对于摄像机位置与方向 ...
- IO多路复用多并发服务器模板
import socket import selectors # IO多路复用选择器 epoll_selector = selectors.EpollSelector() # 实例化选择器 serve ...