树的遍历。

#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)的更多相关文章

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

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

  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 分)(简单,不建树,bfs即可)

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

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

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

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

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

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

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

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

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

  8. PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

    简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  9. PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)

    简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. Linux中切换用户变成-bash4.1-$的解决方法【转】

    转自 Linux中切换用户变成-bash4.1-$的解决方法 - xia_xia的博客 - 博客频道 - CSDN.NEThttp://blog.csdn.net/xia_xia0919/articl ...

  2. 实参时丢弃了类型 discards qualifiers discards qualifiers问题

    百思不得其解,于是百度,google吧.. 发现Stackoverflow上也有人有相同的问题 下面是他的问题: For my compsci class, I am implementing a S ...

  3. 自定义cell,根据数据源,要对cell的布局进行调整,没有实现调整的相应效果

    自定义cell,用于两种显示情况,首次进来A种情况(主材页面),正确显示,然后切换B种情况(辅材情况),可以正确显示,但是当再次切换回A种情况(主材情况)的时候,主材cell不能正常显示了,遗留的B中 ...

  4. swool安装

    swoole安装 安装完PHP后,即可安装swoole扩展. swoole扩展下载地址:https://github.com/swoole/swoole-src/releases 尽量选择stable ...

  5. idea编译报错:未结束的字符串文字;非法的表达式;未结束的字符串字面值

    在idea的Settings中,找到File Encodings,将IDE Encoding 改为UTF-8 要多试几次,清除缓存什么的,具体原因不知道,不过经常第一次修改不能成功.

  6. JS限制 获取动太ID,播放视频

    JS限制textarea字数 function textdown(e) {textevent = e ; ) { return; } ) { alert("大侠,我手机屏幕小,先输入这么多字 ...

  7. php 10.1总

    在做添加时写是否已经有该文件 $_sql1 = "SELECT * FROM tb_user where userName = {$_clean['userName']} "; $ ...

  8. Windows下MySQL分步安装图解及问题总结

    MySQL是一个出色的开源数据库,在易用性和性能方面都有相当不错的表现.就作者发帖为止, MySQL官方发布的所有版本中(4.1/5.0/5.1/6.0),推荐使用稳定的MySQL5.0版本(商用). ...

  9. 【转】Java 内部类种类及使用解析

    Java 内部类种类及使用解析 内部类Inner Class 将相关的类组织在一起,从而降低了命名空间的混乱. 一个内部类可以定义在另一个类里,可以定义在函数里,甚至可以作为一个表达式的一部分. Ja ...

  10. Android中的分页加载

    //----------------------MainActivity中--------------------------------------------------- package com ...