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<stdio.h>
#include<vector>
#include<math.h>
using namespace std; struct Node
{
int level;
vector<int> child;
}; Node Tree[];
bool visit[]; int MAX; vector<int> Maxque; void DFS(int root,int level,double price,double rate)
{
visit[root] = true;
if(Tree[root].child.empty())
{
Maxque.push_back(level);
if(level > MAX ) MAX = level;
}
else
{
for(int i = ;i < Tree[root].child.size();i++)
{
if(visit[Tree[root].child[i]] == false)
DFS(Tree[root].child[i],level+,price,rate);
}
}
} int main()
{
int ID,num,i,root;
double price,rate;
scanf("%d%lf%lf",&num,&price,&rate);
for( i = ; i < num ;i++)
{
Tree[i].child.clear();
visit[i]= false;
}
for(i = ;i < num ;i ++)
{
scanf("%d",&ID);
if(ID != -)
Tree[ID].child.push_back(i);
else root = i;
} int level = ;
MAX = -;
DFS(root,level,price,rate); int count = ;
for(i = ;i< Maxque.size() ;i++)
if( Maxque[i] == MAX ) ++count;
printf("%0.2lf %d\n",price*pow( (+rate)/,MAX),count); return ;
}
1090. Highest Price in Supply Chain (25)的更多相关文章
- [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
1090. Highest 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)(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 ...
- PAT 1090 Highest Price in Supply Chain[较简单]
1090 Highest Price in Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors ...
随机推荐
- Android 高级UI设计笔记08:Android开发者常用的7款Android UI组件(转载)
Android开发是目前最热门的移动开发技术之一,随着开发者的不断努力和Android社区的进步,Android开发技术已经日趋成熟,当然,在Android开源社区中也涌现了很多不错的开源UI项目,它 ...
- 为什么arcgis里,鼠标的图标都变成放大镜不能用了
做作业做到一半,鼠标的图标就只有放大镜了,不管是点箭头还是作图工具都没用,手抓的也没用,只剩下放大镜的功能和图标了,这是怎么一回事啊?种情况我碰到过几次,具体原因不清楚,但是解决方法是有的:把你的数据 ...
- 基于BaseHTTPServer的简单存储服务器
服务器代码: from BaseHTTPServer import BaseHTTPRequestHandler from BaseHTTPServer import HTTPServer impor ...
- [改善Java代码]不要覆写静态方法
建议33: 不要覆写静态方法 我们知道在Java中可以通过覆写(Override)来增强或减弱父类的方法和行为,但覆写是针对非静态方法(也叫做实例方法,只有生成实例才能调用的方法)的,不能针对静态方法 ...
- Netty学习链接
Netty实战精髓请参见:https://waylau.gitbooks.io/essential-netty-in-action/content/GETTING%20STARTED/Introduc ...
- poj 3249 拓扑排序 and 动态规划
思路:我们首先来一遍拓扑排序,将点按先后顺序排列于一维数组中,然后扫描一遍数组,将每个点的出边所连接的点进行更新,即可得到最优解. #include<iostream> #include& ...
- Nginx+FastCGI+C
http://flandycheng.blog.51cto.com/855176/858946 http://www.cnblogs.com/xiaouisme/archive/2012/08/01/ ...
- jquery的datepicker汉化
$("#date").datepicker({ dateFormat: "yy-mm-dd", monthNames:["1月", &quo ...
- css3 渐变记
css3 渐变 线性渐变 径向渐变 重复线性渐变 重复径向渐变 线性渐变 线性渐变接受三个参数,渐变的方向,起始颜色,结束颜色. 标准语法及参数:linear-gradient:([[<angl ...
- Java Concurrency - 线程的基础操作
创建线程 在 Java 中,创建线程有两种方式: 继承 java.lang.Thread 类,重写 run 方法. public class MyJob extends Thread { @Overr ...