PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
简单dfs。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std; const int maxn=+;
vector<int>g[maxn];
int n;
double p,r;
int root;
int ans_x;
double ans_price=; void dfs(int x,double price)
{
if(g[x].size()==)
{
if(price>ans_price)
{
ans_price=price;
ans_x=;
}
else if(price==ans_price)
{
ans_x++;
}
return;
} for(int i=;i<g[x].size();i++)
{
dfs(g[x][i],price*(1.0+r/));
}
} int main()
{
scanf("%d",&n);
scanf("%lf%lf",&p,&r); for(int i=;i<n;i++)
{
int fa; scanf("%d",&fa);
if(fa==-) root=i;
else g[fa].push_back(i);
} dfs(root,p); printf("%.2lf %d\n",ans_price,ans_x); return ;
}
PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)的更多相关文章
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- 【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 ...
- 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)
时间限制 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) 1079. Total Sales of Supply Chain (25)
树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- 1090. Highest Price in Supply Chain (25)-dfs求层数
给出一棵树,在树根出货物的价格为p,然后每往下一层,价格增加r%,求所有叶子节点中的最高价格,以及该层叶子结点个数. #include <iostream> #include <cs ...
随机推荐
- Entity Framework 学习高级篇1—改善EF代码的方法(上)
本节,我们将介绍一些改善EF代码的相关方法,如NoTracking,GetObjectByKey, Include等. l MergeOption.NoTracking 当我们只需要读 ...
- Puppent 介绍原理及安装
Puppet原理: Puppet是一个或者多个master,众多client,所有的客户端都定期(默认为30分钟)使用facter工具把 客户端的基本信息,通过https的xmlrpc协议发送给服务器 ...
- Django 用户认证及OneToOneField
Django 用户认证如果自己不想写 就可以用django自带的认证 首选导入模块 models.py #!/usr/bin/env python #_*_ coding:utf8 _*_ from ...
- sqlserver-根据2张表的id更新其他列值
update a set a.ORGID = (select b.ORG_ID from PT_SERVICE b where a.SERVICEOID = b.SERVICEOID and a.OR ...
- js屏蔽浏览器右键菜单
<script type="text/javascript"> function doNothing(){ window.event.returnValue=false ...
- ABI & API
API defines the programning language and function entry point, arguments type, order. ABI defines th ...
- About struct in C
something new: to set value in struct can be in case i cannot view picture.. i write the snippet her ...
- Camera Path插件的使用
rpg游戏类型的游戏,猪脚走过一个个场景,一个个死角.拐弯处,摄像机镜头也能很好的跟踪对焦,很多朋友都会想,这摄像机如何智能跟踪并且对焦呢? 之前 itween也有demo,但它做法是 两条线,一条摄 ...
- CDN(转载)
CDN是什么? 谈到CDN的作用,可以用8年买火车票的经历来形象比喻: 8年前,还没有火车票代售点一说,12306.cn更是无从说起.那时候火车票还只能在火车站的售票大厅购买,而我所住的小县城并不通火 ...
- Oracle sql优化之分析函数优化标量子查询
待优化语句如下 select a.code as code, a.m_code as m_code,a.stktype as f_stype,a.e_year as e_year, b.sname a ...