1079 Total Sales of Supply Chain (25 分)(树的遍历)
给出一颗销售供应的树,树根唯一。在树根处货物的价格为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 分)(树的遍历)的更多相关文章
- 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)【树+搜索】——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 分)
题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...
- 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点
和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...
- 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 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)
树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- pat1079. Total Sales of Supply Chain (25)
1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- PAT 1079 Total Sales of Supply Chain[比较]
1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...
随机推荐
- 从Java官网下载JDK1.6等低版本JDK
今天在浏览Java官网的时候发现旧版本(1.8之前)的JDK安装包下载地址没有在下载页面明显的提供出来.个人通过在官网查看,发现oracle官方将旧版本的JDK全都放在Java Archive模块中了 ...
- Thinkphp 5 使用DOMDocument
每一个载入浏览器都会生成一个 Document 对象. Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问.Document 对象是 Window 对象的一部分. 我们项目 ...
- 【洛谷P1063】NOIP2006能量项链
能量项链 https://www.luogu.org/problemnew/show/P1063 好像比合并石子更水.. 区间动规,f[l][r]表示合并区间l~r的最大能量 按区间长度dp 枚举中间 ...
- React后台管理系统-品类选择器二级联动组件
1.页面大致是这个样子 2.页面结构 <div className="col-md-10"> <select name="&quo ...
- 2、SpringBoot+Mybatis整合------一对一
开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis01/tree/93398da60c647573645917b2 ...
- java基础语法:非法修饰符组合 abstract
abstract 与 final :abstract 是需要被继承以实现的,final却说你不能被修改,逻辑错误 abstract 与 private:同样的abstract 需要被子类实现,但pr ...
- tomcat.apache startup.bat闪退两种解决方法
tomcat bin文件夹中的startup.bat闪退原因及解决方法两种 方法一:在启动tomcat时闪退,重新检查java的jre运行环境.如果环境变量忘记配置一定会导致了tomcat的闪退. 追 ...
- JQuery发起ajax请求,并在页面动态的添加元素
页面html代码: <li> <div class="coll-tit"><span class="coll-icon">& ...
- Uboot S3C2440 BL1 的流程
1. reset 中断向量表 2. 进入reset (1) 设置svc32 模式 (2) flash I/D caches (3)disable MMU 和 cache (4)2440 没有o ...
- ES6笔记01-声明变量
ES6只有六种声明变量的方法:var命令和function命令,let和const命令,import命令和class命令.所以,ES6一共有6种声明变量的方法. const声明一个只读的常量.一旦声明 ...