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> ...
随机推荐
- 调试minix内核
调试的时候,要把电脑当作单片机来使用,故先需要添加串口,方便进行打印调试 http://wiki.minix3.org/doku.php?id=developersguide:serialout 1. ...
- javascript 为啥不用instanceof检测数组,这里有一个示例坑
前些天写js遇到了一个instanceof的坑,我们的页面中有一个iframe,我在index页面中计算得到了一个array,然后需要传递到Flight页面 这个嵌套的iframe中的一个函数(Sea ...
- android平台编译IW
不知道怎么编译IW,所以就搜索网络上的博客http://blog.csdn.net/jksl007/article/details/16862435 首先,iw依赖于libnl库,而目前android ...
- 报表Reporting S而vice是 错误的解决
Reporting Services 错误 报表服务器无法打开与报表服务器数据库的连接.所有请求和处理都要求与数据库建立连接. (rsReportServerDatabaseUnavailable)获 ...
- sql语句操作表
"create table mytable (m_id integer identity(1,1) primary key,m_class varchar(50) not null defa ...
- 【转】哦,mysql 的其它发行版本Percona, mariadb
原文:http://geek.csdn.net/news/detail/130146 2016年11月25日,沃趣科技"智慧应用 数据先行"2016产品发布会暨新三板挂牌庆祝会在杭 ...
- navicat连接oracle时发现 ORA-12737 set CHS16GBK
oracle安装目录下找到目录:\product\11.2.0\dbhome_1\BIN, 将箭头标注的三个文件(截图中为navicat中的目录,已经测试成功,亲们可以参考)从目录中拷贝纸navica ...
- Git学习 -- 冲突解决
当连个分支对统一文件提交了不同修改时,可能会出现冲突,例如: $ git merge feature1 Auto-merging readme.txt CONFLICT (content): Merg ...
- HDU 2671 Can't be easier
简单的几何题目 点(a,b)关于直线Ax+By+C=1对称点的公式 #include<cstdio> #include<cstring> #include<cmath&g ...
- java设计原则:16种原则
一 类的设计原则 1 依赖倒置原则-Dependency Inversion Principle (DIP) 2 里氏替换原则-Liskov Substitution Principle (L ...