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 S​i​​ is the index of the supplier for the i-th member. S​root​​ 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 ;
}
 

最新文章

  1. CSS3之背景剪裁Background-clip
  2. Android View的绘制机制流程深入详解(一)
  3. PhpForm表单相关的超全局变量操作
  4. hdu 4122 Alice&#39;s mooncake shop(单调队列)
  5. java内部类继承--构造函数传参
  6. js 字符串切割
  7. zookeeper部署
  8. 持续集成时 travis 和 codecov 等 yaml 文件的配置
  9. go语言学习-结构体
  10. Thinkphp 关联模型
  11. Java虚拟机一
  12. nginx信号量
  13. 在centos7升级jenkins
  14. 【LeetCode371】 Sum of Two Integers
  15. layer弹出层效果
  16. EUI组件之DataGroup
  17. 关于IPv4设置一些常见问题的解答
  18. zeromq 笔记
  19. Alpha冲刺(2/10)
  20. jmeter - 命令行方式运行

热门文章

  1. 从士兵到程序员再到SOHO程序员 (二)
  2. 基于docker/虚拟机的esp32远程工作流
  3. SQL 游标示例
  4. 按照eslint 规范写代码 [eslint] &#39;flag&#39; is assigned to itself. (no-self-assign)
  5. Fully qualified domain name for gitlab
  6. 虚拟化(五):vsphere高可用群集与容错(存储DRS是一种可用于将多个数据存储作为单个数据存储群集进行管理的功能)
  7. android开发基础知识了解
  8. Machine Learning in Action(5) SVM算法
  9. 在oc中一些常用的宏定义总结
  10. java基础以及操作Excle