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 ...
随机推荐
- JQuery中常用方法备忘
本文转载自博客园,原文地址 http://www.cnblogs.com/xzf158/archive/2008/10/14/logan.html 1.Window.onload 的JQuery方法 ...
- Ajax应用-Ajax传输JSON数据实例
———————————————————— <script type="text/javascript"> var client; ...
- ice调通过iceReplica用所有server instance的方法---客户端控制服务端的负载均衡
I 使用此方法,可以增量的通知Ice服务配置的改变,刷新每个服务进程的数据 可以手动控制客户端调用的负载均衡,客户端程序决定将请求发往那个进程 上代码: import logging import I ...
- 让AutoMapper在你的项目里飞一会儿(转)
出处:http://www.cnblogs.com/WeiGe/p/3835523.html 先说说DTO DTO是个什么东东? DTO(Data Transfer Object)就是数据传输对象,说 ...
- Server对象(是属性)
html, body { font-size: 10.5pt; } body { font-family: 微软雅黑, Helvetica, "Hiragino Sans GB", ...
- Qt学习之系列[9] – QCoreApplication:processEvents()可能会引起递归,导致栈溢出崩溃
api含义:QCoreApplication::processEvents() 将处理所有事件队列中的事件并返回给调用者. 问题描述: 当主线程在某个槽函数里正在执行processEvents时, 刚 ...
- linq中first() firstordefault() last() lastOrDefault() single() singleOrDeafult
一.firstordefault() 和 first() class Program { static void Main(string[] args) { List<Emp> list ...
- rs.Open sql,conn,0,2,1
例子:rs.Open sql,conn,0,2,1 CursorType = 0,默认值,打开仅向前类型游标.LockType = 2, 开放式锁定Options = 1, 指示 ADO 生成 SQL ...
- 运用Merge Into实现增加或更新数据
declare @SqlStr as nvarchar(max) set @SqlStr=N'Merge Into [Categories] t USING(VALUES (9,''rice'','' ...
- 转:12C CDB and pdb with sql developer
How to install the 12c DB and use the Pluggable DB with SQL DeveloperGoal To give a path to install ...