给出一棵树,在树根出货物的价格为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求层数的更多相关文章

  1. [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)

    1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...

  2. 1090. Highest Price in Supply Chain (25) -计层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  3. 1090. Highest Price in Supply Chain (25)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  4. 1090 Highest Price in Supply Chain (25)(25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  5. PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...

  6. PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)

    简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  7. Highest Price in Supply Chain (25)(DFS)(PAT甲级)

    #include<bits/stdc++.h>using namespace std;int fa;int degree[100007];vector<int>v[100007 ...

  8. 【PAT甲级】1090 Highest Price in Supply Chain (25 分)

    题意: 输入一个正整数N(<=1e5),和两个小数r和f,表示树的结点总数和商品的原价以及每向下一层价格升高的幅度.下一行输入N个结点的父结点,-1表示为根节点.输出最深的叶子结点处购买商品的价 ...

  9. pat1090. Highest Price in Supply Chain (25)

    1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...

随机推荐

  1. PyQt5---ChangeIcon

    # -*- coding:utf-8 -*- ''' Created on Sep 13, 2018 @author: SaShuangYiBing ''' import sys from PyQt5 ...

  2. [python]关于列表增加元素的几种操作

    1.insert方法,该方法包含两个参数,第一个参数为插入的位置参数,第二个参数为插入内容 a = [0,0,0] b = [1,2,3] a.insert(0,b) print a 输出: [[1, ...

  3. 在学习前端的路上,立下一个Flag

    今天开始百度前端学习,以此为证

  4. js字符串String常用方法

    1.   charAt()         返回指定位置的字符. str.charAt(index) index 为必须参数,类型为number(0到str.length-1之间,否则该方法返回 空串 ...

  5. R语言(资源)

    #学习 R 的方法 知识和耐心,是成为强者的唯一方法. - 通过阅读来学习.包括了阅读经典的教材.代码.论文.学习公开课.- 通过牛人来学习.包括同行的聚会.讨论.大牛的博客.微博.twitter.R ...

  6. docker swarm英文文档学习-4-swarm模式如何运行

    1)How nodes work Docker引擎1.12引入了集群模式,使你能够创建一个由一个或多个Docker引擎组成的集群,称为集群.集群由一个或多个节点组成:在群模式下运行Docker引擎1. ...

  7. ICSharpCode.SharpZipLib 开源压缩库使用示例

    官方网站:http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx 插件描述: ICSharpCode.SharpZipLib.dl ...

  8. Linux防火墙工具Firestarter

    Firestarter是一个非常好用的防火墙图形化配置工具,作者和开发者是芬兰人. 首先肯定的说Firestarter防火墙是一款非常优秀的基于GUI图形用户界面下的,完全免费的自由软件,它为中小型L ...

  9. jqgrid 获取选中行主键集合

    如何获取选中行的主键集合呢? 使用  getGridParam(selarrrow) 方法可获取所有选中行的主键集合. 注意:此处的主键集合是指-设置为主键的列(key: true).再次提醒:一个j ...

  10. RTSP server 在mips 上莫名其妙退出(PC上则无此问题)

    http://blog.csdn.net/lubing20044793/article/details/38523701 早在这篇blog以前写过,在虚拟机下调试sn9c291时,USB 数据传输出了 ...