1090 Highest Price in Supply Chain——PAT甲级真题
1090 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 (<=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 6Sample Output:
1.85 2
题目大意:题目大致意思与1079 Total Sales of Supply Chain 相同,无非就是所求结果相同,这道题让你输出可以卖出的最高价格和能卖出最高价格的销售商的人数。
大致思路:利用DFS从根节点往下搜索,记录每个叶子结点的编号方便后续统计价格相同的个数。
代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct node {
vector<int> child;
double sell;
}root[N];
double p, r;
int n;
vector<double> cost;
vector<int> leaf;
double ans = 0.0;
void newNode (int x) {
root[x].sell = 0.0;
root[x].child.clear();
}
void DFS(int x) {
if (root[x].child.size() == 0) {
ans = max(ans, root[x].sell);
leaf.push_back(x);
return;
}
for (int i = 0; i < root[x].child.size(); i++) {
int tmp = root[x].child[i];
root[tmp].sell = (1 + 0.01 * r) * root[x].sell;
DFS(tmp);
}
}
int main() {
scanf("%d%lf%lf", &n, &p, &r);
int root_index;
for (int i = 0; i < n; i++) newNode(i);
for (int i = 0; i < n; i++) {
int s;
scanf("%d",&s);
if (s == -1) {
root_index = i;
continue;
}
root[s].child.push_back(i);
}
root[root_index].sell = p;
DFS(root_index);
int cnt = 0;
for (auto l : leaf) {
if (root[l].sell == ans) cnt++;
}
printf("%.2lf %d\n", ans, cnt);
return 0;
}
1090 Highest Price in Supply Chain——PAT甲级真题的更多相关文章
- 1079 Total Sales of Supply Chain ——PAT甲级真题
1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...
- PAT 1090 Highest Price in Supply Chain[较简单]
1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...
- [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...
- PAT 甲级 1090 Highest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...
- PAT 1090. 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 ...
- 1090 Highest Price in Supply Chain (25 分)(模拟建树,找树的深度)牛客网过,pat没过
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 1090. Highest Price in Supply Chain (25)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
随机推荐
- RESTFul应用分析
Restful API 近年来应用越来越广泛,各大互联网公司纷纷推出了自己的 Restful API 服务. 本文将从实际应用出发,从 REST 到 Restful 再到 Restful API ,逐 ...
- $().arr使用
$("#handmoney").attr("readonly","readonly"); 只读 $("img").att ...
- linux系统磁盘管理(磁盘阵列)
1.磁盘阵列简介 RAID(Redundant Array of Independent Disks)即独立硬盘冗余阵列,简称磁盘阵列.磁盘阵列是由很多价格较便宜的磁盘,以硬件(RAID卡)或软件(M ...
- 使用两个FIFO完成流水操作
一.设计目标 写一个FIFO控制器,控制器里有两个FIFO,输入的数据由串行接收模块(uart_rx_module)送来,一共有86行86列的数据,按0.1.2行,1.2.3行,直到最后83.84.8 ...
- C++的匿名函数(lambda表达式)
总述 C++11提供了对匿名函数的支持,称为Lambda函数(也叫Lambda表达式). 它是定义和使用匿名函数对象的一种简便的方式.匿名函数是我们需要用到的一个函数,但是又不想去费力命名一个函数的 ...
- Ubuntu18.04系统设置为中文语言
1.选择右上角设置按钮 2.管理已安装的语言 3.安装简体中文 安装好后是这样的 会发现汉语中文那一块是灰色的,怎么点都点不亮 4.拖拽 汉语(中国) 到最顶边 然后应用 5.重启 然后就出现这个画面 ...
- CF-125E MST Company (单度限制最小生成树)
参考红宝书 题目链接 对除 1 号点顶点外的点集,求一次最小生成森林,对于最小生成森林的联通分量,选择最短的一条边与 1 号点相连.设此时 1 号点的度为 \(k_0\),如果 \(k_0\lt L\ ...
- 2020第十一届蓝桥杯第二场省赛C++A组【A-H】
A. 门牌制作 答案 624 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_st ...
- hdu3564 Another LIS
Problem Description There is a sequence firstly empty. We begin to add number from 1 to N to the seq ...
- Linux入门详解
Linux基础知识 Linux&Unix 说起Linux,就不得不提Unix操作系统. Unix系统号称世界上最稳定的系统,就连苹果公司也从中获取灵感开发出了移动端大名鼎鼎的IOS. Unix ...