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 ...
随机推荐
- Nginx软件模块说明
Nginx软件模块说明 Nginx常用模块 注:以下只是列举Nginx常用模块,需要详细了解更多模块可以登录Nginx官方网站查看 功能模块 模块说明 ngx_http_core_module 包含一 ...
- 机器突然宕机导致hdfs启动一直超时的行为
今天手里其中一个集群几个机器突然宕机,启动hdfs一直超时. clouder-scm-agent主要报了这个错RROR: Unexpected error 'getpwuid(): uid not f ...
- META标签的定义与使用(二、页面描述信息(NAME))
二.name的content指定实际内容.如:如果指定level(等级)为value(值),则Content可能是beginner(初级).intermediate(中级).advanced(高级). ...
- vc枚举本机端口信息
关于查看本机端口信息,可能大多数人都知道在cmd下的netstat 命令,殊不知该命令在底层也是调用相关api来实现的,相关函数有:GetTcpTableGetExtendedTcpTableGetU ...
- 【bug】vue同一组件使用
vue使用同一个组件渲染,进行切换过程中会存在数据保存的情况. 比如路由切换,进行渲染的页面来自同一个组件,这个时候,要在监听路由的时候,将数据重新初始化
- c_数据结构_二叉树的遍历实现
#include<stdio.h> #include<stdlib.h> #define OK 1 #define ERROR 0 #define OVERFLOW -2 #d ...
- C++: class sizeof
https://blog.csdn.net/fengxinlinux/article/details/72836199 C++中类所占的大小计算,因为涉及到虚函数成员,静态成员,虚继承,多继承以及空类 ...
- leetcode-219-存在重复元素②
题目描述: 第一次提交:超时 class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool ...
- Perl 数据类型
Perl 数据类型 Perl 是一种弱类型语言,所以变量不需要指定类型,Perl 解释器会根据上下文自动选择匹配类型. Perl 有三个基本的数据类型:标量.数组.哈希.以下是这三种数据类型的说明: ...
- Kubernetes的包管理工具Helm的安装和使用
1.源码安装 [root@master ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.0-linux-amd64 ...