[建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
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)的更多相关文章
- [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)
1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- 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)(25 分)
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 ...
- PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 1090. Highest Price in Supply Chain (25)-dfs求层数
给出一棵树,在树根出货物的价格为p,然后每往下一层,价格增加r%,求所有叶子节点中的最高价格,以及该层叶子结点个数. #include <iostream> #include <cs ...
- 【PAT甲级】1090 Highest Price in Supply Chain (25 分)
题意: 输入一个正整数N(<=1e5),和两个小数r和f,表示树的结点总数和商品的原价以及每向下一层价格升高的幅度.下一行输入N个结点的父结点,-1表示为根节点.输出最深的叶子结点处购买商品的价 ...
- pat1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...
随机推荐
- Apache 流框架 Flink,Spark Streaming,Storm对比分析(二)
本文由 网易云发布. 本文内容接上一篇Apache 流框架 Flink,Spark Streaming,Storm对比分析(一) 2.Spark Streaming架构及特性分析 2.1 基本架构 ...
- Markdown新手快速入门基础教程
Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档. 当前许多网站都广泛使用 Markdown 来撰写帮助文档或是用于论坛上发表消息.例如:GitHub.简书.redd ...
- python基础学习1-列表推导式和字典推导式
#!/usr/bin/env python # -*- coding:utf-8 -*- #列表推导式 取得100内可以被2整除且不能被3整除的数字 a=[i for i in range(100) ...
- 洛谷 P3795 钟氏映射
洛谷 P3795 钟氏映射 题目背景 2233年,CSSYZ学校的数学老师兼数学竞赛顾问钟JG已经2200+岁啦! 为了庆生,他或她给广大人民群众出了道题. 题目描述 设集合N=M={x∣x∈N+, ...
- Python之冒泡排序算法
顾名思义,冒泡排序直观的意思是气泡越大冒的越快:),对应到我们的列表中就是数字最大的先选出来,然后依次进行.例如 myList = [1,4,5,0,6],比较方式为: 相邻的两个数字先进行比较,也就 ...
- 约束4:唯一约束,Check约束和null
大家知道,关系型数据库的逻辑运算的结果是三值型的,TRUE,FALSE和UNKNOWN,特别是,NULL值和任何值都不相等,任何值和NULL的比较,返回的逻辑结果都是unknown.而NULL值在唯一 ...
- CSS快速入门-后端布局
一.后台框架概述 我们在网上随便搜索后台框架,你会发现大部分都查不多.正所谓:好看的皮囊千篇一律,有趣的灵魂万里挑一. 第一个是H-ui,H-ui.admin是用H-ui前端框架开发的轻量级网站后台模 ...
- div滤镜结合ajax,实现登录
一:登陆页面 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...
- XAF-由于try catch导致的性能问题一例
前几天在制作PMMS系统时,有天突然发现性能问题下降严重,发布到客户机后,每点击一个按钮要花5-10秒的时间,与本机的200-600毫秒差距很大. 经过多处优化后没有效果. 后来想起,最近增加的功能是 ...
- CAN总线的显性电平为什么能覆盖隐性电平?
摘要:在CAN总线中,显性电平是强驱动,隐性电平时弱驱动,因此当有的节点发送显性电平有的节点发送隐性电平时,总线上呈现的肯定是强驱动的状态,这就是CAN总线显性电平可以覆盖隐性电平的原因. 大家都知道 ...