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<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef struct NODE{
vector<int>child;
}node;
node tree[], root;
int N;
double P, r;
int cnt = ;
double maxSum = -;
void dfs(int root, int depth){ //depth为包括root的层深度
double tempSum = ;
if(tree[root].child.size() == ){
tempSum = P * pow(1.0 + r, depth * 1.0);
if(tempSum > maxSum){
maxSum = tempSum;
cnt = ;
}else if(tempSum == maxSum){
cnt++;
}
return;
}
int len = tree[root].child.size();
for(int i = ; i < len; i++){
dfs(tree[root].child[i], depth + );
}
} int main(){
int tempc, root;
scanf("%d%lf%lf", &N, &P, &r);
r = r / 100.0;
for(int i = ; i < N; i++){
scanf("%d", &tempc);
if(tempc == -){
root = i;
}else{
tree[tempc].child.push_back(i);
}
}
dfs(root, );
printf("%.2f %d", maxSum, cnt);
cin >> N;
return ;
}

总结:

1、仍然是求叶子节点的深度的问题。从根节点到叶子节点层层加价r%,求到叶子节点的最大价格,其实就是求最深的叶子节点深度。

2、题中说-1代表是根节点,最先还以为是说第i个数是-1,代表第i个节点的父亲是根节点。其实是说第i个节点是根节点。

3、题目中是以父亲节点的形式给出一棵树的(输入的第i个数字b,代表b的子节点是i)。

A1090. Highest Price in Supply Chain的更多相关文章

  1. PAT甲级——A1090 Highest Price in Supply Chain

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

  2. PAT_A1090#Highest Price in Supply Chain

    Source: PAT A1090 Highest Price in Supply Chain (25 分) Description: A supply chain is a network of r ...

  3. PAT1090:Highest Price in Supply Chain

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. javascript调用ActiveX接口失败的解决方案及使用心得

    前段时间公司做了个比较大的项目,需要用到ocx控件,我厂大部分项目都采用C#.net,而winform程序条用ocx控件接口是相对简单的,但是javascript调用ocx接口,却和winform的用 ...

  2. 使用阿里云cli管理安全组

    相比于python SDK方式,阿里云基于GO SDK开发了一整套CLI工具,可以通过调用RPC API来管理云资源,对编程能力不够的人来说是个福音. 而且,阿里云CLI的文档比SDK的文档更加全面, ...

  3. TomCat 再次发布我的程序

    打包成.war的步骤就不说了,之后的配置和上一次的不一样. 在Tomcat的conf下的server.xml文件中,重新配置如下 <Service name="xfwweb" ...

  4. 使用Zabbix服务端本地邮箱账号发送报警邮件及指定报警邮件操作记录

    邮件报警有两种情况:1)Zabbix服务端只是单纯的发送报警邮件到指定邮箱,发送报警邮件的这个邮箱账号是Zabbix服务端的本地邮箱账号(例如:root@localhost.localdomain), ...

  5. getUserMedia API及HTML5 调用摄像头和麦克风

    getUserMedia API简介 HTML5的getUserMedia API为用户提供访问硬件设备媒体(摄像头.视频.音频.地理位置等)的接口,基于该接口,开发者可以在不依赖任何浏览器插件的条件 ...

  6. 【转】STM32和ARM的区别

    转自:http://www.cnblogs.com/nuc-boy/archive/2012/09/11/2680157.html 这个问题大概2009年的时候很多人就在问,请看09年的时候大家给出的 ...

  7. PAT 1057 数零壹

    https://pintia.cn/problem-sets/994805260223102976/problems/994805270914383872 给定一串长度不超过 10​5​​ 的字符串, ...

  8. [转自知乎]飞腾国产CPU的部分知识

    1. 作者:常成链接:https://www.zhihu.com/question/48948852/answer/113595308来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...

  9. 一步步分析为什么B+树适合作为索引的结构

    在MySQL中,主要有四种类型的索引,分别为:B-Tree索引,Hash索引,Fulltext索引和R-Tree索引,本文讲的是B-Tree索引. 什么是索引 索引(Index)是帮助数据库高效获取数 ...

  10. loadrunner分析结果二

    5 worst transaction transaction name:事务名 failure ratio[%](exceeded time/transaction duration)失败率 (超标 ...