A1090. 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
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef struct NODE{
vector<int>child;
}node;
node tree[], root;
int N;
double P, r;
int cnt = ;
double maxSum = -;
void dfs(int root, int depth){ //depth为包括root的层深度
double tempSum = ;
if(tree[root].child.size() == ){
tempSum = P * pow(1.0 + r, depth * 1.0);
if(tempSum > maxSum){
maxSum = tempSum;
cnt = ;
}else if(tempSum == maxSum){
cnt++;
}
return;
}
int len = tree[root].child.size();
for(int i = ; i < len; i++){
dfs(tree[root].child[i], depth + );
}
} int main(){
int tempc, root;
scanf("%d%lf%lf", &N, &P, &r);
r = r / 100.0;
for(int i = ; i < N; i++){
scanf("%d", &tempc);
if(tempc == -){
root = i;
}else{
tree[tempc].child.push_back(i);
}
}
dfs(root, );
printf("%.2f %d", maxSum, cnt);
cin >> N;
return ;
}
总结:
1、仍然是求叶子节点的深度的问题。从根节点到叶子节点层层加价r%,求到叶子节点的最大价格,其实就是求最深的叶子节点深度。
2、题中说-1代表是根节点,最先还以为是说第i个数是-1,代表第i个节点的父亲是根节点。其实是说第i个节点是根节点。
3、题目中是以父亲节点的形式给出一棵树的(输入的第i个数字b,代表b的子节点是i)。
A1090. Highest Price in Supply Chain的更多相关文章
- PAT甲级——A1090 Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT_A1090#Highest Price in Supply Chain
Source: PAT A1090 Highest Price in Supply Chain (25 分) Description: A supply chain is a network of r ...
- PAT1090:Highest Price in Supply Chain
1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...
- [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...
- PAT 1090 Highest Price in Supply Chain[较简单]
1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...
- pat1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...
- 1090 Highest Price in Supply Chain——PAT甲级真题
1090 Highest Price in Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), ...
- 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) -计层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
随机推荐
- 基于 HTML5 Canvas 的 3D WebGL 机房创建
对于 3D 机房来说,监控已经不是什么难事,不同的人有不同的做法,今天试着用 HT 写了一个基于 HTML5 的机房,发现果然 HT 简单好用.本例是将灯光.雾化以及 eye 的最大最小距离等等功能在 ...
- BGFX 渲染引擎中着色器代码的调试方法
在实时渲染的图形开发中,着色器代码(Shader)越来越复杂,于是单纯的靠经验和不断试错的开发和调试方法早已不能满足实际需求.使用调试工具进行调试,成为开发中重要的方法.Bgfx 是一款跨平台.抽象封 ...
- Aop笔记
参考: https://blog.csdn.net/bombSKLK/article/details/79143145 示例 拦截的 注解的方法 @Around("@annotation(c ...
- <软件体系结构>实验框架选择及其说明
一.框架选择 本次实验,我所采取的框架是SSH框架.那么首先,我想简单的说明一下SSH框架,一方面给自己复习一下知识,另一方面也能使自己在以后看这篇博客的时候不至于太费力. SSH不是一个框架,而是S ...
- Github的建立及心得体会
第一次接触Github,这次注册最大的难处就是全英文,着实看不懂.仅凭着认识的几个常用词去了解个具体内容实在是太困难了.所以第一个体会就是要好好学英语背单词,不想看到满屏的英文就感觉头疼,烦躁.第二个 ...
- synchronized关键字的学习与总结
- 批处理-For详解
大纲 一 前言 二 for语句的基本用法 三 for /f (delims.tokens.skip.eol.userbackq.变量延迟) 四 for /r (递归遍历) 五 for /d (遍历目录 ...
- 前端存储loaclForage
以前使用本地存储,首先会想到localstorage或者session storage,将要存储的数据转化成字符串后进行setItem操作,但是使用local storage 有几个问题: 1.它是同 ...
- ubuntu python apache2 wsgi django框架
在ubuntu上通过apatch2和wsgi部署django (亲手做过!!!) 一,我的python.django.apatch2版本: python:python -V 2.7.3 django: ...
- c++ 为自定义类添加stl遍历器风格的遍历方式
为仿照stl的遍历风格,实现对自定义类型的遍历. 1. 需要遍历的基础结构: struct ConnectionPtr { int id_; int port_; string addr_; //st ...