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 ...
随机推荐
- node.js 笔记一
现在地址:http://nodejs.org/download/ 我的机器是windows的,选择的文件是,是编译后的版本:Windows Installer (.msi) 32-bit examp ...
- [工具]iperf测试带宽
之前被要求测试网卡带宽能力,发现了iperf这个工具,记录下来防止遗忘. iperf是个开源跨平台测试带宽工具,windows.linux.macOS--都支持,安装也挺方便. 1.安装 地址:htt ...
- Redis系列九:redis集群高可用
Redis集群的概念: RedisCluster是redis的分布式解决方案,在3.0版本后推出的方案,有效地解决了Redis分布式的需求,当一个服务挂了可以快速的切换到另外一个服务,当遇到单机内存. ...
- etcd管理
操作etcd有命令行工具etcdctl,有两个api版本互不兼容的,系统默认的v2版本,kubernetes集群使用的是v3版本,v2版本下是看不到v3版本的数据的,我也是找了些资料才了解这个情况. ...
- Linux下安装与配置snmp服务
一.安装snmp服务 1.检查系统是否已经安装snmp的rpm包 以下是安装snmp服务需要的rpm包: libsensors3-2.10.6-55.el5.i386.rpm lm_sensors-2 ...
- WorldWind源码剖析系列:网络下载类WebDownload
网络下载类WebDownload封装了对请求的瓦片进行网络下载的相关操作.该类使用了两个委托类型和一个枚举类型. 该类的类图如下. 网络下载类WebDownload各个字段和属性的含义说明如下: st ...
- sql的一个查询,情景:a表中存在的数据,且在b表中不存在 (not in,not exists
这里需要强调的是b表中关联字段的值是唯一的这种情况,并且b表尽量是列举类型的,意味着表比较小. ==================== 准备数据: 1. 建两个类似表,test1,test2,只有i ...
- Python实现随机读取文本N行数据
工作中需要判断某个文本中的URL是否能正常访问,并且随机获取其中N行能正常访问的URL数据,我的思路是:读取文本每一行数据,用urlopen访问,将返回状态码为200的URL保存到一个列表,获得列表长 ...
- 20155305《网络对抗》MSF基础应用
20155305<网络对抗>MSF基础应用 实验过程 实验系统 靶机1:Windows XP Professional SP2 ,IP地址:192.168.1.108 靶机2:Window ...
- linux下使用软连接之案例二
在笔者的上一篇文章介绍过怎么通过linux的软连接在不修改上传代码的情况下,将上传到项目路径下的图片改为上传到项目外面,防止重新部署后图片被删除了.同时还可以直接通过类似访问静态资源的方 ...