1090. Highest Price in Supply Chain (25)

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
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; const int maxn=1e5+;
const int INF=1e9;
struct Node
{
int data;
vector<int> child;
}node[maxn]; int max_deep=;
int layer[maxn]={}; void dfs(int s,int &deep)
{
if(node[s].child.size()==)
{
layer[deep]+=;
max_deep=max_deep>deep?max_deep:deep;
return ;
}
for(int i=;i<node[s].child.size();i++)
{
int v=node[s].child[i];
deep+=;
dfs(v,deep);
deep-=;
}
} int main()
{
int n;
double p,r;
cin>>n>>p>>r;
int root;
for(int i=;i<n;i++)
{
int f;
////scanf("%d",&f);
cin>>f;
if(f==-)
{
root=i;
continue;
}
node[f].child.push_back(i); }
int deep=;
dfs(root,deep);
double sum=p;
int tmp=max_deep;
while(tmp>)
{
tmp--;
sum*=(+r/.);
}
printf("%.2lf %d\n",sum,layer[max_deep]);
}

[建树(非二叉树)] 1090. Highest Price in Supply Chain (25)的更多相关文章

  1. [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)

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

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

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

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

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

  4. 1090 Highest Price in Supply Chain (25)(25 分)

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

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

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

  6. PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)

    简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  7. 1090. Highest Price in Supply Chain (25)-dfs求层数

    给出一棵树,在树根出货物的价格为p,然后每往下一层,价格增加r%,求所有叶子节点中的最高价格,以及该层叶子结点个数. #include <iostream> #include <cs ...

  8. 【PAT甲级】1090 Highest Price in Supply Chain (25 分)

    题意: 输入一个正整数N(<=1e5),和两个小数r和f,表示树的结点总数和商品的原价以及每向下一层价格升高的幅度.下一行输入N个结点的父结点,-1表示为根节点.输出最深的叶子结点处购买商品的价 ...

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

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

随机推荐

  1. PyQt5 笔记(05):信号/槽

    PyQt 的很多类都内置了信号和槽.下图是 Qt 官方文档对 QThread 类中包含的信号/槽的描述: 一.信号/槽 都是内置的 请看一个最简单的程序: 按钮点击后,窗口关闭 代码: class T ...

  2. 【转载】特殊宏://{{AFX_MSG、//{{AFX_VIRTUAL、//{{AFX_MSG_MAP、//{{AFX_DATA_INIT

    原文:http://yyguangzheng.blog.163.com/blog/static/603488402014102215153610/ 说明:这篇日志我不知道怎么命名好,虽然内容很少,但是 ...

  3. C++实现tar包解析

    tar(tape archive)是Unix和类Unix系统上文件打包工具,可以将多个文件合并为一个文件,使用tar工具打出来的包称为tar包.一般打包后的文件名后缀为".tar" ...

  4. Codeforces 469 D. Two Sets (并查集)

    题目链接:Two Sets 题意: 有n个数,要分成A.B两组,要求如果x∈A则a-x∈A,如果x∈B则b-x∈B,问是否存在一种符合要求的分法. 题解: 并查集,先增加两个点表示A和B集合的根,对于 ...

  5. 通过IDEA解决spring配置文件

    来自:https://blog.csdn.net/yanghanxiu/article/details/79366263 (其实尼可以使用springboot 这样就不用配置一大堆东西了喵!) 每次创 ...

  6. STM8S——Clock control(CLK)

    1.主时钟源 有四种时钟源可以用做主时钟: (1)1-24MHz高速外部晶体振荡器(HSE) (2)最大24MHz高速外部时钟信号(HSE user-ext) (3)16MHz高速内部RC振荡器(HS ...

  7. Map.containsKey(String key)

    判断key有没有对应的value值有,返回true无,返回false

  8. 关于SDK-manager中我们需要下载哪些?

    废话少说,直接看图说话…… 图片取自博客文章——链接跳转:点击跳转

  9. SecureCRT 用法总结

    SecureCRT 用法总结   1.下载与破解方法: Mac:https://www.jianshu.com/p/9427f12b1fdb Window:https://drive.google.c ...

  10. tomcat9在centos7上启动慢问题

    /opt/java/jdk1.8.0_162/jre/lib/security/java.security 将如下配置securerandom.source=file:/dev/random 改为se ...