PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)
树的遍历。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=+;
vector<int>tree[maxn];
int n;
double P,r;
double sum;
int sz;
int num[maxn]; void dfs(int x,double price)
{
if(tree[x].size()==)
{
sum=sum+num[x]*price;
sz++;
return;
} for(int i=;i<tree[x].size();i++)
dfs(tree[x][i],price*(+r/)*1.0);
}
int main()
{
scanf("%d",&n);
scanf("%lf%lf",&P,&r);
for(int i=;i<n;i++)
{
int ki; scanf("%d",&ki); if(ki==)
{
int x; scanf("%d",&x);
num[i]=x;
}
else
{
while(ki--)
{
int to; scanf("%d",&to);
tree[i].push_back(to);
}
}
} sum=;sz=;
dfs(,P);
printf("%.1lf\n",sum); return ;
}
PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)的更多相关文章
- 【PAT甲级】1079 Total Sales of Supply Chain (25 分)
题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...
- 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 ...
- 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)-求数的层次和叶子节点
和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...
- 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 ...
- 1079. Total Sales of Supply Chain (25) -记录层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- Head First--设计模式(装饰者模式)
从现在开始,我将以写一个小软件的方式来进行模式识别的学习,包含需求分析,功能模块设计,原理图设计,程序实现这个几个部分,可能具体的模式模块不可能都包括在内. 需求分析:星巴兹咖啡店已经遍布全世界的很多 ...
- 关于PHP静态方法调用和实例化类调用的区别
1.首先来澄清一些观点 由于静态方法在内存中只有一份,无论你调用多少次,都是共用的,而且没有对象的概念,所以不能在静态方法里面使用$this调用,如果非得调用的话,只能实例化自身类 而实例化不一样,每 ...
- namenode ha
http://blog.csdn.net/totxian/article/details/45248399 http://www.aboutyun.com/thread-13679-1-1.html ...
- sql中 replace函数
例用 xxx 替换 abcdefghi 中的字符串 cde. SELECT REPLACE(''abcdefghicde'',''cde'',''xxx'')
- SQL 优化案例 1
create or replace procedure SP_GET_NEWEST_CAPTCHA( v_ACCOUNT_ID in VARCHAR2, --接收短信的手机号 v_Tail_num i ...
- 常见html标签
1.flash嵌入标签 <object> <embed allowscriptaccess="always" allowfullscreen="true ...
- 【A + B + C + D】 问题
A + B + C + D Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- [转]java static final 初始化
http://tanbing1986411.blog.163.com/blog/static/7259798220103610224434/ java static final 初始化 1.stati ...
- Linux中的挂载和卸载
mkdir /home/xxx 创建挂载点 mount /dev/cdrom /home/xxx 把cdrom中的内容挂载到xxx目录 umount /dev/cdrom 卸载 /dev/sr ...
- HDU - 1702 ACboy needs your help again!(栈和队列)
Description ACboy was kidnapped!! he miss his mother very much and is very scare now.You can't image ...