1090. Highest Price in Supply Chain (25)-dfs求层数
给出一棵树,在树根出货物的价格为p,然后每往下一层,价格增加r%,求所有叶子节点中的最高价格,以及该层叶子结点个数。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
/*
相当于求解树的层数
*/
using namespace std;
const int maxn=+;
int maxlayer=,num=;
int head[maxn];
int tot; struct Edge{
int to;
int next;
}edge[maxn]; void init(){
tot=;
memset(head,-,sizeof(head));
}
void add(int u,int v){
edge[tot].next=head[u];
edge[tot].to=v;
head[u]=tot++;
}
void dfs(int u,int layer){
if(head[u]==-){
if(layer>maxlayer){
maxlayer=layer;
num=;
}
else if(layer==maxlayer)
num++;
return;
}
for(int k=head[u];k!=-;k=edge[k].next){
int v=edge[k].to;
dfs(v,layer+);
}
} int main()
{
int v,root;
int n;
double p,r;
scanf("%d %lf %lf",&n,&p,&r);
init();
for(int i=;i<n;i++){
scanf("%d",&v);
if(v==-)
root=i;
else
add(v,i);
}
dfs(root,);
double ans=p*pow(+r/,maxlayer);
printf("%.2lf %d",ans,num);
return ;
}
1090. Highest Price in Supply Chain (25)-dfs求层数的更多相关文章
- [建树(非二叉树)] 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 ...
- 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 1090 Highest Price in Supply Chain (25) [树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...
- PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- Highest Price in Supply Chain (25)(DFS)(PAT甲级)
#include<bits/stdc++.h>using namespace std;int fa;int degree[100007];vector<int>v[100007 ...
- 【PAT甲级】1090 Highest Price in Supply Chain (25 分)
题意: 输入一个正整数N(<=1e5),和两个小数r和f,表示树的结点总数和商品的原价以及每向下一层价格升高的幅度.下一行输入N个结点的父结点,-1表示为根节点.输出最深的叶子结点处购买商品的价 ...
- pat1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...
随机推荐
- October 15th 2017 Week 42nd Sunday
Excellence is a continuous process and not an accident. 卓越是一个持续的过程而不是一个偶然事件. It is said that ten tho ...
- 2017 SDN第一次作业
(1)我会选择的,因为网络现在越来越重要,各行各业都离不开网络,这个方向可以适合各种岗位,感觉比较容易就业.但选这个课是为了多学一点东西,没想太多,嘎嘎嘎. (2)SDNLAB,是一个SDN的大的中文 ...
- 并发编程概述--C#并发编程经典实例
优秀软件的一个关键特征就是具有并发性.过去的几十年,我们可以进行并发编程,但是难度很大.以前,并发性软件的编写.调试和维护都很难,这导致很多开发人员为图省事放弃了并发编程.新版.NET 中的程序库和语 ...
- 【洛谷】【单调栈】P4333 [COI2007] Patrik
--接上一篇题解,[洛谷][单调栈]P1823音乐会的等待 关于题目大意在上一篇题解里已经说清楚了,这里不再多阐述 想看题目->戳这里 [算法分析:] 在对元素a进行判断时,如果它与栈顶元素相等 ...
- CVE-2017-8046(Spring Data Rest RCE)
环境搭建参考第一个链接,springboot启动文件如下,不同的启类,将Application.class修改一下就可以了,直接debug.注意:默认版本是2.0.3版本,修改成低版本,看一下mvn下 ...
- opencv——对象提取与测量
#include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespac ...
- Python3.6+nginx+uwsgi部署Django程序到阿里云Ubuntu16.04系统
Python3.6+nginx+uwsgi部署Django程序到阿里云Ubuntu16.04系统 这个是写好的Django程序在本地机运行的情况,一个查询接口. 准备工作 1.首先购买一台阿里云的EC ...
- odoo tree视图 当页不弹窗显示方法
<xpath expr="//tree" position="attributes"> <attribute name='editable'& ...
- 【Python实践-7】输出100以内的所有素数
#输出100以内的所有素数,素数之间以一个空格区分(注意,最后一个数字之后不能有空格). i= l=[] : k= ,i): : k=k+ : l.append(i) i=i+ print(" ...
- [清华集训2015 Day2]矩阵变换-[稳定婚姻模型]
Description 给出一个N行M列的矩阵,保证满足以下性质: M>N. 矩阵中每个数都是 [0,N]中的自然数. 每行中, [1,N]中每个自然数刚好出现一次,其余的都是0. 每列中,[1 ...