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 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 Si is the index of the supplier for the i-th member. Sroot 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
简单搜索
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
double p,per;
vector<int> v[];
double a[];
void dfs(int x,double y)
{
if(v[x].size()==)
{
a[x] = y ;
return ;
}
if(x==){
for(int i=;i<v[x].size() ;i++ )
{
dfs( v[x][i],y );
}
}
else{
for(int i=;i<v[x].size() ;i++ )
{
dfs( v[x][i],y*per );
}
}
}
bool cmp(double a,double b)
{
return a>b;
}
int main()
{
memset(a,,sizeof(a));
scanf("%d %lf %lf",&n,&p,&per);
per = (+per)/;
for(int i=;i<n;i++)
{
scanf("%d",&k);
if(k==-)
{
v[].push_back(i);
}
else
{
v[k].push_back(i);
}
}
dfs( , p);
sort(a,a+n,cmp);
double maxn = a[];
int count1=;
for(int i=;i<n;i++)
{
if(a[i] == maxn)
{
count1++;
}
}
printf("%.2lf %d\n",maxn,count1);
return ;
}
1090 Highest Price in Supply Chain (25 分)的更多相关文章
- 【PAT甲级】1090 Highest Price in Supply Chain (25 分)
题意: 输入一个正整数N(<=1e5),和两个小数r和f,表示树的结点总数和商品的原价以及每向下一层价格升高的幅度.下一行输入N个结点的父结点,-1表示为根节点.输出最深的叶子结点处购买商品的价 ...
- [建树(非二叉树)] 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 ...
- 1090. Highest Price in Supply Chain (25)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- 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 ...
- 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 ...
随机推荐
- C语言的面向对象设计之 X264,FFMPEG 架构探讨
FFMPEG架构分析 使用面向对象的办法来设想这样一个编解码库,首先让人想到的是构造各种编解码器的类,然后对于它们的抽象基类确定运行数据流的规则,根据算法转换输入输出对象. 在实际的代码,将这些编解码 ...
- AppStore审核--17.5
本文转载至 http://blog.csdn.net/addychen/article/details/39672185 感谢原文作者分享 AppStore审核 为了确保用户理解应用如何使用他们的数据 ...
- Quick UDP Internet Connections
https://blog.chromium.org/2013/06/experimenting-with-quic.html user datagram protocol transport laye ...
- 创建私有maven库
在公司搭建私有maven库,我为了在本机做测试,我选择Sonatype nexus oss,在docker里面安装 1.Mac上安装docker 下载地址:https://github.com/boo ...
- 设置开启telnet功能
今天访问服务器的时候发现ip可以ping通,但是不能访问,就telnet一下端口吧,谁知系统逗我:
- ORACLE函数之单行转换函数
1 ASCIISTR 格式:ASCIISTR(C) 说明:将字符串C转换为ASCII字符串,即将C中的ASCII字符保留不变,但非ASCII字符则以ASCII表示返回 举例: ...
- vim实现代码缩进和可视区域的字符串替换
今天2014年9月12号,实现了vim下的代码自动缩进和替换可视区域的字符串,之前一直在用vim这个强大的编辑器,它的强大只有用了的人才知道,现在把这两个很强大的功能展示出来,有个这两个功能,即使你写 ...
- XMPP学习笔记 -- RFC 6120
XMPP - Extensible Messaging and Presence Protocol 1. 中文版3920 http://wiki.jabbercn.org/RFC3920 2. 大部分 ...
- [haoi2015]T1
题意:给定你一颗树,要求你在这棵树中确定K个黑点和N-K个白点,使黑点间与白点间两两距离之和最大,输出最大值.n<=2000 对于这道题,我想了好几个思路,包括点分治,贪心,动规,网络流等等,实 ...
- SDUT OJ 2088 refresh的停车场
refresh的停车场 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 refresh最近发了一笔横财,开了一家停车场.由于土地 ...