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. Linux下DNS简单部署(主从域名服务器)

    一.DNS简介DNS(Domain Name System),域名系统,因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串.通 ...

  2. Centos下SVN环境部署记录

    大多数情况下,我们日常工作中用的版本控制系统都会选择分布式的Git,它相比于集中式的SVN有很多优势.但是有些项目软件基于自身限制,可能只支持SVN做工程同步.废话就不多说了,下面记录下SVN的部署和 ...

  3. Jenkins新建项目中源码管理Repository URL使用Git报错:Failed to connect to repository : Command "git ls-remote -h......

    之前部署了Gitlab+Gerrit+Jenkins持续集成环境,但在Jenkins中新建项目的源码管理"Repository URL"中添加git地址环节出现了问题,信息为&qu ...

  4. 软件项目第一次Sprint总结

    成果评分表: 组名 分数 原因 9-652 6 界面和谐生动,可运行,在目前阶段可时间基本操作 hzsy -2 代码下载,但实现安卓和相机调用 JYJe族 -1 实现安卓界面,完成一项功能,做得少 结 ...

  5. TitleLayout——一个Android轻松实现通用、标准、支持沉浸式状态栏的标题栏库

    TitleLayout 多功能.通用的.可在布局或者使用Java代码实现标题栏:支持沉浸式状态栏,支持左侧返回按钮(不需要手动实现页面返回),左侧支持图片+文字.图片.文字:右侧支持图片.文字等. 堆 ...

  6. PAT 甲级 1135 Is It A Red-Black Tree

    https://pintia.cn/problem-sets/994805342720868352/problems/994805346063728640 There is a kind of bal ...

  7. WIN10快捷键

    WIN10快捷键 多桌面切换:WIN + CTRL +  ←/→ 桌面横竖屏转向:ALT + CTRL +  ←/→

  8. curl用法一例 传递代理用户名密码

    curl -u bb0e1736d66744495b814b942fd04a80:0e11dda88048ed52cc8758caf06dc6b4 https://jinshuju.net/api/v ...

  9. 【转帖】intel 2018年1 月2号爆出漏洞分析 知乎匿名用户

    作者:匿名用户链接:https://www.zhihu.com/question/265012502/answer/288407097来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...

  10. Qt__CMakeLists.txt

    cmake_minimum_required(VERSION 3.1.0) project (Project) if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_CXX_FL ...