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 6

Sample 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甲级真题的更多相关文章

  1. 1079 Total Sales of Supply Chain ——PAT甲级真题

    1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...

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

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

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

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

  4. PAT 甲级 1090 Highest Price in Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...

  5. PAT 1090. Highest Price in Supply Chain

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

  6. PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...

  7. 1090 Highest Price in Supply Chain (25 分)(模拟建树,找树的深度)牛客网过,pat没过

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

  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. mysql错误(Incorrect key file for table)

    Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to repair it mysql错误:mysql需要 ...

  2. JavaScript解构赋值

    JavaScript解构赋值 JavaScript解构赋值为我们提供了很多方便,但是用法比较多,本文就来梳理一下.总体来说,主要就两种地方使用解构赋值,一种是数组的解构赋值,另一种是对象的解构赋值.以 ...

  3. sql如何查询数据库最后10条记录并正序输出

    select * from (select * from 表名 order by 字段 desc limit 10) 临时表 order by 字段

  4. 前端基础之html学习一:

    网站的建站流程 页面图例 网页的结构 WEB标准 WEB标准是网页制作的标准,它不是一个标准,它是根据网页的不同组成部分生成的一系列标准.这些标准大部分由W3C起草发布,也有部分标准由ECMA起草发布 ...

  5. Web APP和原生 APP的不同

    我们现在手机中的APP,大部分都是混合APP,也就是既用到了原生APP的基础,又用到了Web APP的基础,混合的比例从0%到100%之间不等.更好的了解APP的类型,有助于我们学则合适的测试策略.今 ...

  6. 2019牛客暑期多校训练营(第五场)G-subsequence 1

    >传送门< 题意:给你两个数字字符串s,t,求字符串s的子序列比字符串t大的个数 思路:他的题解上写的就是dp的基础练习题,好像的确是这么回事,既然是dp,那么对于定义的状态不同得到的转移 ...

  7. HDOJ 1078

    标准的DAG上的DP,其实之前一直不大想得明白为什么dp[i][j]为什么一定是在(i,j)状态上的局部最优解了呢? 其实仔细想想和我一般所做的DP是一个道理,因为运用dfs的方法,因此可以确定的是, ...

  8. hdu5643 King's Game(约瑟夫环+线段树)

    Problem Description In order to remember history, King plans to play losephus problem in the parade ...

  9. fzu2198 快来快来数一数

    Accept: 204    Submit: 627 Time Limit: 1000 mSec    Memory Limit : 65536 KB  Problem Description n个六 ...

  10. 放苹果 POJ - 1664 递推

    把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. Input 第一行是测试数据的数目t(0 <= t < ...