Source:

PAT A1090 Highest Price in Supply Chain (25 分)

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 S​i​​ is the index of the supplier for the i-th member. S​root​​ 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的更多相关文章

  1. PAT1090:Highest Price in Supply Chain

    1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...

  2. [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)

    1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...

  3. PAT 1090 Highest Price in Supply Chain[较简单]

    1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...

  4. pat1090. Highest Price in Supply Chain (25)

    1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...

  5. 1090 Highest Price in Supply Chain——PAT甲级真题

    1090 Highest Price in Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), ...

  6. 1090. Highest Price in Supply Chain (25)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  7. 1090. Highest Price in Supply Chain (25) -计层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  8. A1090. Highest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. PAT 甲级 1090 Highest Price in Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...

随机推荐

  1. (转)OpenFire源码学习之七:组(用户群)与花名册(用户好友)

    转:http://blog.csdn.net/huwenfeng_2011/article/details/43413651 Group 在openfire中的gorop——组,也可以理解为共享组.什 ...

  2. (转)OpenFire源码学习之二:Mina基础知识

    转:http://blog.csdn.net/huwenfeng_2011/article/details/43413009 Mina概述 Apache MINA(Multipurpose Infra ...

  3. 线程创建后为什么要调用CloseHandle

    很多程序在创建线程都这样写的: ............ ThreadHandle = CreateThread(NULL,0,.....); CloseHandel(ThreadHandle );  ...

  4. git入门基本命令

    第一个命令 git init (repo_dir) 初始化git版本库,如果省略repo_dir的话,那么就把当前目录作为git库进行初始化. 第二个命令 git status 查看版本库状态,随时可 ...

  5. 《深入理解Java虚拟机》-(实战)boolean类型在虚拟机中是如何处理的

    这里先引出Java的8大基本类型.直接上图吧. 可以看到,除了boolean和char类型之外,越往下的类型的值域是包含以上的值域的.因此,从上面的基本类型转换成下面的基本类型,无需强制转换.关于它们 ...

  6. js 点击获取验证码后的倒数60s

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script ...

  7. <Linux>Linux基础学习(兄弟连版本)

    1.Linux系统简介 1.1 Unix与Linux发展史 父子关系:Unix 是Linux的前身 1969年,肯丶汤姆森开发Unix系统(为了加快玩游戏的速度 - -,自己开发的系统) 1971年, ...

  8. python--接口类与抽象类

    一. 继承有两种用途: """ 一:继承基类的方法,并且做出自己的改变或者扩展(代码重用) 二:声明某个子类兼容于某基类,定义一个接口类Interface,接口类中定义了 ...

  9. 解决MSF更新证书错误

    如下图所示提示签名无效下载失败,导致更新不了msf 解决办法如下: echo 'deb http://apt.metasploit.com/ lucid main' > /etc/apt/sou ...

  10. OneDrive一直后台占用CPU的一种解决办法

    系统版本:Windows 7 ultimate x64 Onedrive版本:17.3.6998.0830 最近发现Onedrive一直在后台占用15%左右的CPU,很是觉得奇怪,网上的解决方案是删除 ...