PAT_A1090#Highest Price in Supply Chain
Source:
Description:
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 Pand 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 (≤), 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 −. 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 1.
Sample Input:
9 1.80 1.00
1 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2
Keys:
Code:
/*
time: 2019-06-28 15:10:32
problem: PAT_A1090#Highest Price in Supply Chain
AC: 15:50 题目大意:
根结点价格为P,结点深度增加一层,溢价r%,求最高价格
第一行给出:结点数N<=1e5(0~n-1),p,r
第二行给出,N个数,第i个数表示,结点i的父结点,根结点为-1 基本思路:
求最大深度及其叶子结点个数
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int M=1e5+;
vector<int> tree[M];
int maxDeep=,cnt=; void Travel(int root, int hight)
{
if(tree[root].size() == )
{
if(maxDeep < hight)
{
maxDeep = hight;
cnt=;
}
else if(maxDeep == hight)
cnt++;
return;
}
for(int i=; i<tree[root].size(); i++)
Travel(tree[root][i],hight+);
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,father,root;
double p,r;
scanf("%d%lf%lf", &n,&p,&r);
for(int i=; i<n; i++)
{
scanf("%d", &father);
if(father == -){
root = i;
continue;
}
tree[father].push_back(i);
}
Travel(root,);
printf("%.2f %d", p*pow((+r/),maxDeep-), cnt); return ;
}
PAT_A1090#Highest Price in Supply Chain的更多相关文章
- PAT1090:Highest Price in Supply Chain
1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...
- [建树(非二叉树)] 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[较简单]
1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...
- pat1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...
- 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)
时间限制 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 ...
- A1090. Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT 甲级 1090 Highest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...
随机推荐
- yield列表反转 islice切片(2.6)
yield列表反转 islice切片 列表反转 l1 = [i for i in range(10)] print(l1) print(l1[::2]) l1.reverse() # 注: pytho ...
- Python的从头再来
虽然各种视频,文档看了不少.但是都没有系统的总结.现在要把Python从最基础开始总结,回归.也当作自己的复习.
- 关于RF做自动化大致流程的梳理
RF只是一个框架,类似于单元测试框架,可以实现对用例的有效管理.结合其它第三方库,可以进行,接口,数据库,APP的自动化测试.结合JENKINS,还可以进行有效的持续集成. 本文不讲调用第三方库的哪些 ...
- ubuntu ceph集群安装以及简单使用
ubuntu ceph安装以及使用 1.安装环境 本文主要根据官方文档使用ubuntu14.04安装ceph集群,并且简单熟悉其基本操作.整个集群包括一个admin节点(admin node,主机名为 ...
- 2014 mathtype分块列向量输入 PPT动画制作
1.mathtype分块列向量的输入 http://zhidao.baidu.com/link?url=pV7TazWe-Ld5qgxNcJCQdRaA8ILEgmXRP211F5U0Cst0xNfU ...
- centos7.5下生成公钥,实现ssh免密钥登陆
配置SSH无密码登录需要4步准备工作生成公钥和私钥导入公钥到认证文件,更改权限测试1. 准备工作确认本机sshd的配置文件(需要root权限) # vi /etc/ssh/sshd_config 1找 ...
- python--常用模块:collections 、time、random
一.collections 模块 1:nametuple 生成可以用名字访问内容的元祖 from collections import namedtuple point=namedtuple('p ...
- Kettle使用kettle.properties
kettle.properties 是一个变量文件,这个文件我使用的最多的地方是保存 “数据库连接” 用户名和密码. 如果不用这个文件,那么使用“数据库连接”时,需要硬编码写到文件里. 有一天dba告 ...
- 框架_mybatis1
mybatis框架是实现与数据之间交互 入门: 创建数据库环境 创建实体类与数据库对应字段 实现Serializable 创建接口定义方法 创建主配置方法: <?xml version=&quo ...
- Linux 进程间通信 共享内存
1.特点: 1)共享内存是一种最为高效的进程间通信方式,进程可以直接读写内存,而不需要任何数据的拷贝.如管道当在内核空间创建以后,用户空间需要内存 拷贝,需要拷贝数据,所以效率低. 2)为了在多个进 ...