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 ...
随机推荐
- selenium 百度登陆
using System;using OpenQA.Selenium;using OpenQA.Selenium.Firefox;//引用命名空间using System.IO; using Syst ...
- openwrt ramips随记
ar71xx / brcm47xx / brcm63xx / ramips是指cpu的系列,ramips是指ralink系列的
- ocs添加仓库受限问题
添加仓库时受限出现以下问题 如图: 解决方法 修改app\ome\lib\branch\func.php文件的allow_use_num方法 /** * 允许使用的仓库数 * @access publ ...
- StartSSL证书申请
StartSSL官方地址: http://www.startssl.com/ 申请过程: 1)填写资料 2) 获取得验证码 3)提交验证码,等待6小时审核. 4)再次获得验证码,提交等待审核 5)审核 ...
- vs远程调试
一.远程 建立共享目录debug 二.本地 1.生成->输出->输出路径,由"bin\Debug\"改为远程目录"\\xxx\\debug&quo ...
- Linux下的编程实战【转】
一篇比较不错的文章, 降到了 makefile make , gcc编译器,GDB调试器, Linux文件系统,Linux文件API,.C语言库函数(C库函数的文件操作实际上是独立于具体的操作系统平台 ...
- 转载,find.sh
#!/bin/bash #find files contains a keyword #write by xiaojing.zhao #2012.12.14 echo -e "\nThis ...
- java应用测试报告生成(二):利用ant的build.xml生成测试报告
1.将写好的项目导出 在工程下会生成一个build.xml的蚂蚁图标的文件. 2.右击该文件,选择run as Ant build 其中的测试目录是可以选择的,如果涉及到顺序也可以调整顺序 3.执行后 ...
- 2014 Shanghai Invitation Contest
题目链接 http://acm.hdu.edu.cn/search.php?field=problem&key=2014%C9%CF%BA%A3%C8%AB%B9%FA%D1%FB%C7%EB ...
- 内联函数 inline 漫谈
内联函数存在的结论是: 引入内联函数是为了解决函数调用效率的问题 由于函数之间的调用,会从一个内存地址调到另外一个内存地址,当函数调用完毕之后还会返回原来函数执行的地址.函数调用会有一定的时间开销,引 ...