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 ;
}

最新文章

  1. Which ports are considered unsafe on Chrome
  2. ubuntu下code::blocks+opengl的使用与配置
  3. 多线程访问winform控件出现异常的解决方法
  4. bzoj 3124 [Sdoi2013]直径(dfs)
  5. 挂载磁盘的问题(/dev/sdb1 is apparently in use by the system; will not make a 文件系统 here!)
  6. python 重载 __hash__ __eq__
  7. Linux系统配置成简单的路由器
  8. ASCII Art (English)
  9. 笔记︱信用风险模型(申请评分、行为评分)与数据准备(违约期限、WOE转化)
  10. 《高级软件测试》Linux平台Jira的安装与配置
  11. Java JWT: JSON Web Token
  12. 第一次c语言上机
  13. Python读写txt文件时的编码问题
  14. C语言之指针变量
  15. ubuntu下好用的音乐播放器audacious
  16. 关于Android 主题的那些事
  17. Scrapy学习篇(二)之常用命令行工具
  18. Hudson 打包部署到Was上特别慢
  19. 干货: 可视化项目实战经验分享,轻松玩转 Bokeh (建议收藏)
  20. Java从零开始学十(Arrays类对数组的常用方法)

热门文章

  1. Delphi Base64编码_解码及ZLib压缩_解压(转)
  2. 吉首大学校赛 I 滑稽树上滑稽果 (Lucas + 莫队)
  3. js中浏览器对象BOM
  4. visual_c++外挂教程(详细)
  5. 如何在一个for语句中迭代多个对象(2.7)
  6. 清理Visual Studio解决方案临时文件:Clean Visual Studio Solution Temporary File Build20160418
  7. 【SQL】事务回滚
  8. python使用threading获取线程函数返回值的实现方法
  9. 机器学习基石笔记:Homework #4 Regularization&amp;Validation相关习题
  10. 作用域 {}代码块 const修饰符 引用