Highest Price in Supply Chain (25)(DFS)(PAT甲级)
#include<bits/stdc++.h>
using namespace std;
int fa;
int degree[100007];
vector<int>v[100007];
void dfs(int x){
for(auto&it:v[x]){
degree[it]=degree[x]+1;
dfs(it);
}
return;
}
double qpow(double x,int y){
double ans=1,tmp=x;
while(y){
if(y&1)
ans*=tmp;
tmp*=tmp;
y>>=1;
}
return ans;
}
int main(){
int n;
double p,r;
scanf("%d%lf%lf",&n,&p,&r);
int root=0;
for(int i=0;i<n;++i){
scanf("%d",&fa);
if(fa==-1)
root=i;
else
v[fa].push_back(i);
}
dfs(root);
int mx=0;
for(int i=0;i<n;++i)
mx=max(mx,degree[i]);
int num=0;
for(int i=0;i<n;++i)
if(degree[i]==mx)
num++;
double ans=p*qpow(1.0+r/100,mx);
printf("%.2f %d",ans,num);
return 0;
}
Highest Price in Supply Chain (25)(DFS)(PAT甲级)的更多相关文章
- 1090. Highest Price in Supply Chain (25)-dfs求层数
给出一棵树,在树根出货物的价格为p,然后每往下一层,价格增加r%,求所有叶子节点中的最高价格,以及该层叶子结点个数. #include <iostream> #include <cs ...
- [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
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 (25) -计层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...
- PAT Advanced 1106 Lowest Price in Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- 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 Level) 1090. Highest Price in Supply Chain (25)
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- 仿联想商城laravel实战---7、lavarel中如何给用户发送邮件
仿联想商城laravel实战---7.lavarel中如何给用户发送邮件 一.总结 一句话总结: 设置邮件服务器,比如163邮箱 lavarel中配置邮件服务,在.env中 控制器中使用Mail对象发 ...
- django1.8.3搭建博客——1
系统:elementary os python 2.7.6 django 1.8.3 1.安装django 先安装pip sudo apt-get install python3-pip 安装dj ...
- 理解WCF(第二部分,部分參考他人)
該篇的主題:wcf到底是怎工作的? 一.什么是分布式: 首先看一张图: 由上图对比我们可以发现,区别就是前者把服务器放在了一台电脑上,而后者把服务器放在了多台电脑上.这样多台电脑处理起来的速度比一台电 ...
- 更新github上代码
前面一篇已经实现首次上传代码到github了,本篇继续讲如何把本地更新的代码同步更新到github上 一.clone代码 1.把大神的代码clone到本地,或者clone自己github上的代码,使用 ...
- Python基础-os、sys模块
一,os模块import os ,sysos.system('ipconfig')#执行操作系统命令,获取不到返回结果 os.popen()#也可以执行操作系统命令,可以返回命令执行结果,但需要rea ...
- Debian for ARM install python 3.5.x
/********************************************************************************** * Debian for ARM ...
- python 3 serial module install
/************************************************************************* * python 3 serial module ...
- Gym - 100570C: Subrect Query (巧妙的单调队列)
De Prezer loves rectangles.He has a n × m rectangle which there is a number in each of its cells. We ...
- HDU1370Biorhythms(中国剩余定理||暴力)
Some people believe that there are three cycles in a person's life that start the day he or she is b ...
- JEECG datagrid 列表检索条件 添加下拉级联功能
$("#communityId").change( function(){ var id = $(this).children('option:selected').val(); ...