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. 【LeetCode 12】整数转罗马数字

    题目链接 [题解] (涨知识了..原来罗马数字是这么回事.. 把{1,4,5,9,10,40,50,90,100,400,500,900,1000}这些东西的罗马数字放在一个数组里面. 每次从大到小减 ...

  2. Mac上安装Android SDK

    今天开始学习IOS,所以先买了个设备先,但是开始使用了苹果本,还是需要继续开发Android,因为那是我现在吃饭的东西,所以就需要在Mac上配置Android SDK,原以为安装SDK很简单,和Win ...

  3. JVM内存分为哪几部分?各个部分的作用是什么?

    JVM内存区域分为五个部分,分别是堆,方法区,虚拟机栈,本地方法栈,程序计数器. 堆. 堆是Java对象的存储区域,任何用new字段分配的Java对象实例和数组,都被分配在堆上,Java堆可使用-Xm ...

  4. delphi下运行vbscript脚本

    简单一个vb脚本,功能为打开被限制的注册表.Set wso = CreateObject("WScript.Shell")wso.RegWrite "HKEY_CURRE ...

  5. Hbase节点的管理|服役和退役节点

    Base节点的管理 1.服役(commissioning) 当启动regionserver时,regionserver会向Hmaster注册并开始接收本地数据,开始的时候,新加入的节点不会有任何数据, ...

  6. 深入理解C指针第一章小结1

    1.1 指针和内存,C程序在编译后,会以三种形式使用内存. (1) 静态/全局内存:在程序开始时分配,程序结束才消失,所有函数都能访问全局变量,static静态变量的作用域局限在定义它们的函数内部 ( ...

  7. [转] Linux下编写脚本实现Daemon

    在Linux(以Redhat Linux Enterprise Edition 5.3为例)下,有时需要编写Service.Service也是程序,一般随系统启动用户不干预就不退出的程序,可以称为Se ...

  8. form提交跳转问题

    $.ajax({ type: "POST", url: url, data: $('.form-horizontal').serialize(), 提交form表单 success ...

  9. POJ 1265 Area (Pick定理 & 多边形面积)

    题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...

  10. vscode eslint插件对vue文件无效

    vscode配置好了之后,只对.js文件提示 vue文件没有效果 改成如下配置就好了. "eslint.validate": [ "javascript", & ...