PAT甲级——A1090 Highest Price in Supply Chain
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 (≤), 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
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
int N, root, maxL = , resN = , level[] = { };
double p, r;
vector<int>G[];;
void BFS(int root)
{
queue<int>q;
q.push(root);
while (!q.empty())
{
root = q.front();
q.pop();
for (auto a : G[root])
{
level[a] = level[root] + ;
if (maxL < level[a])
{
maxL = level[a];
resN = ;
}
else if (maxL == level[a])
resN++;
if (G[a].size() > )
q.push(a);
}
}
}
void DFS(int root)
{
if (G[root].size() == )
return;
for (auto a : G[root])
{
level[a] = level[root] + ;
if (maxL < level[a])
{
maxL = level[a];
resN = ;
}
else if (maxL == level[a])
resN++;
DFS(a);
}
}
int main()
{
cin >> N >> p >> r;
int a;
for (int i = ; i < N; ++i)
{
cin >> a;
if (a == -)
root = i;
else
G[a].push_back(i);
}
//BFS(root);
DFS(root);
printf("%.2f %d\n", p*pow(1.0 + r / 100.0, maxL), resN);
return ;
}
PAT甲级——A1090 Highest Price in Supply Chain的更多相关文章
- PAT 甲级 1090 Highest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...
- PAT甲级——1106 Lowest Price in Supply Chain(BFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90444872 1106 Lowest Price in Supp ...
- A1090. Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...
- PAT 甲级 1106 Lowest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464 A supply chain is a ne ...
- PAT甲级——A1106 Lowest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 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 ...
- 1090 Highest Price in Supply Chain——PAT甲级真题
1090 Highest Price in Supply Chain 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 ...
随机推荐
- 2018今日头条湖北省赛【H】
[题目链接]https://www.nowcoder.com/acm/contest/104/G 现场赛的H题,emmm...C++选手表示很伤心.高精度压四位板子WA四发. 题意很简单就是给你n个数 ...
- capserjs-prototype(中)
evaluateOrDie() 具体样式: evaluateOrDie(Function fn[, String message, int status]) Evaluates an expressi ...
- Font Awesome (Mark)
Font Awesome为您提供可缩放的矢量图标,您可以使用CSS所提供的所有特性对它们进行更改,包括:大小.颜色.阴影或者其它任何支持的效果. 一个字库,675个图标 仅一个Font Awesome ...
- ransformResourcesWithMergeJavaResForDebug问题
错误内容: Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > java.i ...
- Date()日期转换和简单计算
/** * 判断是否为闰年 * @param year * @return */ public boolean isLeap ( int year ) { if ( (year % 4 == 0 &a ...
- 最大流Dinic算法的一些优化 [网络流][最大流]
明天省夏要讲网络流啦!晚上翻出自己的模板发现是蓝书模板QwQ..拿出以前的提交代码(AC过的?) 曾经的提交记录 在luogu上重新提交一遍,结果gg...OVO 没有去除多余的inline 去除了多 ...
- 广义欧拉降幂(欧拉定理)——bzoj3884,fzu1759
广义欧拉降幂对于狭义欧拉降幂任然适用 https://blog.csdn.net/qq_37632935/article/details/81264965?tdsourcetag=s_pctim_ai ...
- js--判断当前环境是否为app环境
/** *判断是否是app环境 */ function getIsApp () { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/ ...
- Unable to find explicit activity class报错问题解决方法
转:http://hi.baidu.com/mz_mz/item/f5672ad814e1ce30e2108f69 1.首先查看是否在已经在AndroidMainfest.xml中添加了你的Activ ...
- VS2010-MFC(状态栏的使用详解)
转自:http://www.jizhuomi.com/software/219.html 上一节讲了工具栏的创建.停靠与使用,本节来讲解状态栏的知识. 状态栏简介 状态栏相信大家在很多窗口中都能见到, ...