和下面是同类型的题目,只不过问的不一样罢了:

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)-求数的层次和叶子节点的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

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

  4. PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

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

  5. 1079. Total Sales of Supply Chain (25)

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

  6. PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)

    树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  7. 【PAT甲级】1079 Total Sales of Supply Chain (25 分)

    题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...

  8. pat1079. Total Sales of Supply Chain (25)

    1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  9. PAT 1079 Total Sales of Supply Chain[比较]

    1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...

随机推荐

  1. easyui学习笔记14-拓展的基本验证规则

    /** * 扩展的基本校验规则, */ $.extend($.fn.validatebox.defaults.rules, { minLength : { // 判断最小长度 validator : ...

  2. NetworkX 图网络处理工具包

    简单介绍 NetworkX is a Python package for the creation, manipulation, and study of the structure, dynami ...

  3. 8.1Solr API使用(分页,高亮)

    转载请出自出处:http://www.cnblogs.com/hd3013779515/ 一.Solr Deep Paging(深分页) 长期以来,我们一直有一个深分页问题.如果直接跳到很靠后的页数, ...

  4. Oracle_spatial的空间操作符介绍

    空间操作符 一.主要空间操作符 1.SDO_FILTER SDO_FILTER(geometry1, geometry2, param); 判断两个几何体是否有相交 SELECT c.mkt_id, ...

  5. python第三十课--异常(with as操作)

    演示with...as...操作 path=r'kaifanglist1.txt' with open(path,'r',encoding='utf-8') as fr: print(fr.read( ...

  6. Volley源码分析(四)NetWork与ResponseDelivery工作原理

    这篇文章主要分析网络请求和结果交付的过程. NetWork工作原理 之前已经说到通过mNetWork.performRequest()方法来得到NetResponse,看一下该方法具体的执行流程,pe ...

  7. 如何删除VS2015中的OpenCV的配置

    首先,在C盘--用户--AppData--Local--Microsoft--MSBuild--v4.0  路径下,找到  Microsoft.Cpp.Win32.user  文件,用记事本打开,如下 ...

  8. JAVA框架 Mybaits 核心配置

    一:mybaits的核心配置文件:SqlMapConfig.xml 配置文件中需要关注的属性: 二.properites属性:一般引用配置文件(properites文件)比如:数据库的配置.我们可以编 ...

  9. jsp运算符

    一.执行运算: 支持四则运算.关系(>;<....),逻辑运算(&&.||) 注意: +:只能进行加法运算,字符串形式的数字可以进行加法运算,这里的+号不能进行字符串的拼接 ...

  10. 评定星级的前端显示js

    五颗星的星级评定: 说明:假设是利用三种图片显示星级评定,即 1.满亮的星 2.半亮的星星 3.不亮的星星: 满分是5分:(此处当然可以作为一个参数可变 函数传入参数grade表示当前分值. func ...