Source:

PAT A1090 Highest Price in Supply Chain (25 分)

Description:

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 Pand 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 S​i​​ is the index of the supplier for the i-th member. S​root​​ 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

Keys:

Code:

 /*
time: 2019-06-28 15:10:32
problem: PAT_A1090#Highest Price in Supply Chain
AC: 15:50 题目大意:
根结点价格为P,结点深度增加一层,溢价r%,求最高价格
第一行给出:结点数N<=1e5(0~n-1),p,r
第二行给出,N个数,第i个数表示,结点i的父结点,根结点为-1 基本思路:
求最大深度及其叶子结点个数
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int M=1e5+;
vector<int> tree[M];
int maxDeep=,cnt=; void Travel(int root, int hight)
{
if(tree[root].size() == )
{
if(maxDeep < hight)
{
maxDeep = hight;
cnt=;
}
else if(maxDeep == hight)
cnt++;
return;
}
for(int i=; i<tree[root].size(); i++)
Travel(tree[root][i],hight+);
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,father,root;
double p,r;
scanf("%d%lf%lf", &n,&p,&r);
for(int i=; i<n; i++)
{
scanf("%d", &father);
if(father == -){
root = i;
continue;
}
tree[father].push_back(i);
}
Travel(root,);
printf("%.2f %d", p*pow((+r/),maxDeep-), cnt); return ;
}

PAT_A1090#Highest Price in Supply Chain的更多相关文章

  1. PAT1090:Highest Price in Supply Chain

    1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...

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

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

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

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

  4. pat1090. Highest Price in Supply Chain (25)

    1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...

  5. 1090 Highest Price in Supply Chain——PAT甲级真题

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

  6. 1090. Highest Price in Supply Chain (25)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  7. 1090. Highest Price in Supply Chain (25) -计层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  8. A1090. Highest Price in Supply Chain

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

  9. PAT 甲级 1090 Highest Price in Supply Chain

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

随机推荐

  1. 线段树区间合并优化dp——cf1197E(好)

    线段树优化dp的常见套路题,就是先按某个参数排序,然后按这个下标建立线段树,再去优化dp 本题由于要维护两个数据:最小值和对应的方案数,所以用线段树区间合并 /* dp[i]表示第i个套娃作为最内层的 ...

  2. action通信机制

    当service通信不能很好的完成任务时候, actionlib则可以比较适合实现长时间的通信过程, actionlib通信过程可以随时被查看过程进度, 也可以终止请求, 这样的一个特性, 使得它在一 ...

  3. elementUI拿到当前表格行的数据的另一种写法

    背景: 这里是通过点击“修改”按钮后才拿到当前行的数据,不是点击当前行任意位置拿到数据,所以不能用 @row-click 方法 改用点击的时候直接拿到这个表里面的这一条数据 1.绑定事件 <te ...

  4. HTML标签类总结

    1.a标签除了可以作为连接也可以发送邮箱,a标签里的文本颜色不能继承父级的. 2.有几个特殊的块级元素只能包含内嵌元素,不能再包含块级元素,这几个特殊的标签是:h1.h2.h3.h4.h5.h6.p. ...

  5. Extjs各版本的下载链接,包含ext3.4源码示例

    最近在维护一个老平台,用的是ext3.4,老东西在网上找示例发现既然还有人收钱,谷歌了一下总算找到了一位免费的发布的,感谢 yipanbo 分享 Extjs的版本繁多,本文收集了Extjs各个版本的下 ...

  6. AutoCAD2016简体中文破解版32位64位下载

    AutoCAD2016序列号:666-69696969 667-98989898 400-45454545 066-66666666(任意一个) AutoCAD2016产品密钥:001H1 AutoC ...

  7. UVA 10522 Height to Area(知三角形三高求面积)

    思路:海伦公式, AC代码: #include<bits/stdc++.h> using namespace std; int main() { int n; scanf("%d ...

  8. 2019秋Java课程总结&实验总结一

    1.打印输出所有的"水仙花数",所谓"水仙花数"是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个"水仙花数". 实验源码: ...

  9. hdu6321 /// 状压DP

    题目大意: 将一个 顶点不重复的边 的边集称为图中的matching 在一个n个点的零图中进行m次操作 + u v为在u v之间加一条边 存在重边 - u v为去掉u v之间的一条边 每次操作后 输出 ...

  10. jp@gc - Stepping Thread Group (deprecated)

      并发6个用户,线程之前不等待,每隔3秒增加1个用户,间隔时间是2秒,然后并发数增加完成之后,运行60秒,运行完成后,每1秒钟停止2个用户