1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点
和下面是同类型的题目,只不过问的不一样罢了:
1090. Highest Price in Supply Chain (25)-dfs求层数
1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
using namespace std;
/*
计算最小的层数与该层数上的叶子节点数目即可
建树用的是链式前向星模板,不了解的参考:
http://www.cnblogs.com/chenxiwenruo/p/4513754.html
*/
const int maxn=+;
int product[maxn];
int head[maxn];
int tot=;
double sum=,p,r;
int cnt=;
struct Edge{
int to,next;
}edge[maxn];
void add(int x,int y){
edge[tot].next=head[x];
edge[tot].to=y;
head[x]=tot++;
}
void init(){
memset(head,-,sizeof(head));
tot=;
} void dfs(int i,int layer){
if(head[i]==-){
sum+=product[i]*p*pow(+r/,layer);
return;
}
for(int k=head[i];k!=-;k=edge[k].next){
int v=edge[k].to;
dfs(v,layer+);
}
}
int main()
{
int n;
scanf("%d %lf %lf",&n,&p,&r);
int a,b;
memset(product,,sizeof(product));
init();
for(int i=;i<n;i++){
scanf("%d",&a);
if(a==){
scanf("%d",&product[i]);
}
for(int j=;j<a;j++){
scanf("%d",&b);
add(i,b);
}
}
dfs(,);
printf("%.1lf",sum);
return ;
}
1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点的更多相关文章
- PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)
1079 Total Sales of Supply Chain (25 分) A supply chain is a network of retailers(零售商), distributor ...
- 1079. Total Sales of Supply Chain (25)【树+搜索】——PAT (Advanced Level) Practise
题目信息 1079. Total Sales of Supply Chain (25) 时间限制250 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is ...
- 1079. Total Sales of Supply Chain (25) -记录层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- 1079. Total Sales of Supply Chain (25)
时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)
树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- 【PAT甲级】1079 Total Sales of Supply Chain (25 分)
题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...
- pat1079. Total Sales of Supply Chain (25)
1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- PAT 1079 Total Sales of Supply Chain[比较]
1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...
随机推荐
- Linux第三课——目录操作
ls 列出目录下的文件及子目录 ls -l 以列表的方式显示详细信息 ls -a 显示所有的 包括隐藏文件 ls -A 显示除了 . ..以外的任何文件 ls -i 显示文件的节点号 ls --col ...
- python第四十课——构造函数
1.动态给对象添加属性: 在对象创建完毕后,单独为其添加需要的属性:可以理解为:私人定制 [注意]: 添加的属性只有此对象能够使用,别的对象如果用了,直接报错; 2.构造函数/构造方法/构造器: 格式 ...
- Android安全测试
- 安装 Autoconf, Automake & Libtool
今天在使用sudo apt-get install命令安装autoconf和automake时,出现了问题,说是不能sudo apt-get install安装这些软件似乎不是最新的.由此,我通过搜索 ...
- WorldWind源码剖析系列:星球球体的加载与渲染
WorldWind源码剖析系列:星球球体的加载与渲染 WorldWind中主函数Main()的分析 在文件WorldWind.cs中主函数Main()阐明了WorldWind的初始化运行机制(如图1所 ...
- python生成语谱图
语音的时域分析和频域分析是语音分析的两种重要方法,但是都存在着局限性.时域分析对语音信号的频率特性没有直观的了解,频域特性中又没有语音信号随时间的变化关系.而语谱图综合了时域和频域的优点,明显的显示出 ...
- 关于YARN Node Labels的一点理解
最近在做实验,实验需要进行分区域计算,网上查了资料后发现Yarn Node Labels + Capacity-Scheduler可以实现我的需求 但是当任务提交到capacity-scheduler ...
- WebView之javascript与android交互基础加强
一.什么是js与android交互? 通俗一点就是使用js代码调用java代码,或者使用java代码调用js代码. 二.为什么要使用js与java代码交互? 1.可以做一些js网页做本身处理不了的事情 ...
- Jmeter—控件
Jmeter有许多控件,可以在我们模拟测试请求时使用. Jmeter共有这8类控件: 配置元件—Http请求默认值 作用:仅设置一次目标URL服务器地址,之后不需要每次请求都写完整的,仅写相对地址就可 ...
- day78
昨日回顾: forms组件: -校验数据(最重要) -先定义一个类(继承Form) -写一些要校验的字段(好多类型) -字段(对象)有一些属性(最长多少,最短多少,是否必填,l ...