【PAT甲级】1090 Highest Price in Supply Chain (25 分)
题意:
输入一个正整数N(<=1e5),和两个小数r和f,表示树的结点总数和商品的原价以及每向下一层价格升高的幅度。下一行输入N个结点的父结点,-1表示为根节点。输出最深的叶子结点处购买商品的价格以及有几个深度最深的结点。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[];
vector<int>v[];
int mx;
int ans[];
void dfs(int x,int storey){
mx=max(mx,storey);
ans[x]=storey;
for(auto it:v[x])
dfs(it,storey+);
}
int main(){
int n;
int root=;
double p,r;
cin>>n>>p>>r;
for(int i=;i<=n;++i){
cin>>a[i];
if(a[i]==-)
root=i-;
else
v[a[i]].push_back(i-);
}
dfs(root,);
int num=;
for(int i=;i<n;++i)
if(ans[i]==mx)
++num;
double sum=p*pow(+r/100.0,mx);
printf("%.2lf %d",sum,num);
return ;
}
【PAT甲级】1090 Highest Price in Supply Chain (25 分)的更多相关文章
- PAT 甲级 1090 Highest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...
- PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...
- [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...
- PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)
1079 Total Sales of Supply Chain (25 分) A supply chain is a network of retailers(零售商), distributor ...
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- PAT甲级——A1090 Highest Price in Supply Chain
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 ...
- 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> ...
随机推荐
- 【STM32H7教程】第59章 STM32H7的DAC基础知识和HAL库API
完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第59章 STM32H7的DAC基础知识和HAL库 ...
- CSS布局的四种定位方式
1.static(静态定位): 默认值.没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明).参考上篇随笔. 2.relative(相对 ...
- 给html元素添加自定义属性,并且用jquery进行筛选
例如有多个div,想要实现类似radio的效果. <div name="teacher" selected="selected">tch1</ ...
- spring(二):体系结构&核心模块
Spring框架 帮助管理对象及其依赖关系 提供如通用日志记录.性能统计.安全控制.异常处理等面向切面的能力 帮助管理数据库事务,提供了一套简单的JDBC访问实现,提供与第三方数据访问框架集成(如Hi ...
- php设计模式之工厂方法实例代码
实现不修改原代码,扩展新功能 <?php header("Content-type:text/html;charset=utf-8"); /** * db接口 * 实现连接数 ...
- [C#] 委托与匿名方法
using System; namespace 匿名函数 { class Program { delegate void TestDelegate(string s); static void M(s ...
- 题解【POJ2155】Matrix
Description Given an \(N \times N\) matrix \(A\), whose elements are either \(0\) or \(1\). \(A[i, j ...
- 题解 【Codeforces387B】George and Round
以下选自官方题解: 考虑困难的需求数量,我们将覆盖这些困难, 然后我们将提出新的问题,并准备新的问题来覆盖其他需求. 很明显,如果我们决定满足从n中抽取i的要求,那么最好采用那些复杂性最小的要求. 让 ...
- 解决:配置虚拟主机,重启apache,[warn] _default_ VirtualHost overlap on port 80, the first has precedence
http://blog.csdn.net/kaizhu_qin/article/details/17506293 很多第一次配置apache的虚拟主机的时候,以为配置第一个虚拟主机完成以后,以后就不会 ...
- 哪款C语言编译器(IDE)适合初学者?
这里我们把“编译器”和“IDE(集成开发环境)”当做一个概念,不再加以区分. C语言的集成开发环境有很多种,尤其是 Windows 下,多如牛毛,初学者往往不知道该如何选择,本节我们就针对 Windo ...