给出一颗销售供应的树,树根唯一。在树根处货物的价格为p,然后从根节点开始没往结点走一层,该层的货物价格将会在父节点的价格上增加r%。给出每个叶节点的货物量求出他们的价格之和

#include<bits/stdc++.h>

using namespace std;
const int N=1e5+;
struct node
{
int data;
vector<int>child;
}s[N];
double price,rate;
double sum=;
void dfs(int v,int step)
{
//cout<<v<<" "<<step<<endl;
if(s[v].child.size()==){
sum+=s[v].data*1.0*pow(+rate/100.0,step);
return;
}
for(int i=;i<s[v].child.size();i++){
dfs(s[v].child[i],step+);
} }
int main()
{
int n;
scanf("%d %lf %lf",&n,&price,&rate);
for(int i=;i<n;i++){
int k;
scanf("%d",&k);
if(k!=){
for(int j=;j<k;j++){
int x;
scanf("%d",&x);
s[i].child.push_back(x);
}
}
else{
int x;
scanf("%d",&x);
s[i].data=x;
}
}
dfs(,);
printf("%.1f\n",sum*price*1.0);
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. 【PAT甲级】1079 Total Sales of Supply Chain (25 分)

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

  4. 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点

    和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...

  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. 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

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

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

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

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

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

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

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

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

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

随机推荐

  1. Codeforces Round #347 (Div.2)_B. Rebus

    题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...

  2. 【转】android中的Style与Theme

    Android默认情况下提供了一些实用的主题样式,比如说Theme.Dialog可以让你的Activity变成一个窗口风格,而Theme.Light则让你的整个Activity具有白色的背景,而不是黑 ...

  3. GDB调试手册[转]

    Linux 包含了一个叫gdb 的GNU 调试程序.gdb 是一个用来调试C和C++程序的强力调试器.它使你能在程序运行时观察程序的内部结构和内存的使用情况.以下是 gdb 所提供的一些功能:它使你能 ...

  4. P3391 【模板】文艺平衡树(Splay)

    Splay #include<cstdio> #include<algorithm> #include<iostream> using namespace std; ...

  5. JavaScript模拟Form提交

    在一个系统跳转到另外一个系统中时,可以用WAS的全局安全性,也可以用共享session做单点登陆,这次接触到了js模拟form提交的方式. function loginOAForm(url) { va ...

  6. Thinkphp 取消Url默认模块的现实

    例子http://www.tp.com/home/index/index 想要现实的效果是:http://www.tp.com/index/index 1是通过配置路由来达到目的 2通过配置首页的入口 ...

  7. JAVA / MySql 编程——第五章 事务、视图、索引、备份和恢复

    1.事务(Transaction): 事务是将一系列数据操作绑成一个整体进行统一管理. 如果一事务执行成功,则咋子该事务中进行的所有数据更改均会提交,称为数据库中的永久成部分. 如果事务执行是遇到错误 ...

  8. stat.h头文件,轻松获取文件属性

    [以前还为了获取文件的长度,费劲从头读取一遍,一个一个字节的算. 做webserver时候,发现原来stat函数可以返回一个结构,里面包括文件的全部属性. 真是曲折啊.] #i nclude<s ...

  9. poj 2965 枚举+DFS

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25343 ...

  10. linux-shell——04

    mv 移动文件或者目录 格式:mv [选项]      源文件/目录     目标文件/目录 注:若移动目标位置与源位置相同(当前下操作),则此操作相当于重命名(改名) ex: [root@local ...