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> ...
随机推荐
- SSAS——基础
一.Analysis Services Analysis Services是用于决策支持和BI解决方案的数据引擎.它提供报表和客户端中使用的分析数据. 它可在多用途数据模型中创建高性能查询结构,业务逻 ...
- Git教程(二)-如何上传和同步自己的git项目
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! Git接触并使用多年, 工作中使用较多,它的分布式存储,使每个人的电脑均为服务器的策略非常棒:再加上 ...
- 纯css实现3D字体
下面分别是html,css和js代码: <div class="wrapper"> <h1 contenteditable data-heading=" ...
- javaScript-进阶篇(三)
1.Window对象 window对象是BOM的核心,window对象指当前的浏览器窗口. window对象方法: 2.JavaScript 计时器 在JavaScript中,我们可以在设定的时间间隔 ...
- curl常用命令行总结
curl 有时HTTP服务接口写完,需要验证下接口功能,这个使用用curl最合适了 curl 全称 command line url viewer curl www.taobao.com curl w ...
- 嵌套list的实例化
在LeetCode上遇到这样返回值 public class Solution { public List<List<Integer>> levelOrder(TreeNode ...
- 数据库ACID和mvcc
一.数据库的ACID性: 原子性(atomicity).一致性(consistency).隔离性(isolation).持久性(durability). 二.原子性 1.原子性:一个事务要么全部完成, ...
- HDU5446 Unknown Treasure(组合数膜合数-->Lucas+中国剩余定理)
>On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown ...
- 标准模板库(STL)学习指南之set集合
set是关联容器.其键值就是实值,实值就是键值,不可以有重复,所以我们不能通过set的迭代器来改变set的元素的值,set拥有和list相同的特性:当对他进行插入和删除操作的时候,操作之前的迭代器依然 ...
- (转载)[机器学习] Coursera ML笔记 - 监督学习(Supervised Learning) - Representation
[机器学习] Coursera ML笔记 - 监督学习(Supervised Learning) - Representation http://blog.csdn.net/walilk/articl ...