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

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. CSS布局(三) 布局模型

    布局模型 在网页中,元素有三种布局模型:1.流动模型(Flow) 默认的2.浮动模型 (Float)3.层模型(Layer) 1.流动模型(Flow) 流动(Flow)模型是默认的网页布局模式.也就是 ...

  2. 菜鸟对APP界面设计的一些心得小结

    1. 前言 当我看着我以前做的一些app界面,我意识到我应该把我的界面设计能力水平再提升一个,因为实在是丑啊!贴一些以前的设计: 现在看来,是不能看的了.我主要是做需求设计,后面也有一些美工的工作,我 ...

  3. 复杂json的解析:jsonobject与jsonArray的使用

    String parameter = { success : 0, errorMsg : "错误消息", data : { total : "总记录数", ro ...

  4. SSL/TLS Diffie-Hellman Modulus <= 1024 位 (LogJam) 使用2048位或更高的Diffie-Hellman

    1.http://slproweb.com/products/Win32OpenSSL.html  下载 SSL 并安装 2.设置环境变量,例如工具安装在C:\OpenSSL-Win64,则将C:\O ...

  5. 技术分享之AQS——内容提要

    1. 背景 最近团队内部技术分享,我做了个关于AQS的分享.ppt中涵盖的部分要点内容,现在整理到博客上. 关于AQS本身的源码解读,可以参考我之前的博文. 2. 要点梳理 下面是一些技术分享的要点梳 ...

  6. Python接口自动化--requests 1

    # _*_ encoding:utf-8 _*_ import requests #请求博客园首页,无参数的get请求 r = requests.get('http://www.cnblogs.com ...

  7. String----是一个对象

    * 字符串可以看成是字符组成的数组,但是js中没有字符类型 * 字符是一个一个的,在别的语言中字符用一对单引号括起来 * 在js中字符串可以使用单引号也可以使用双引号 * 因为字符串可以看成是数组,所 ...

  8. bip32

    https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki RECENT CHANGES: (16 Apr 2013) Added p ...

  9. 通过HttpWebRequest调用webService

    调用远端接口,向远端接口写入一个xml文件(loginLog为xml的字符串).关键方法如下: public object InsertAuditLog(string loginLog) { //Ws ...

  10. CAN总线典型特征

    CAN总线典型特征 2016-04-12 20:36:54来源: eefocus 关键字:CAN总线  典型特征   收藏 评论(0) 分享到 微博 QQ 微信 LinkedIn CAN总线有如下基本 ...