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(经 ...
随机推荐
- 转:adb操作命令详解及大全
说到 ADB 大家应该都不陌生,即 Android Debug Bridge,Android调试桥,身为 Android 开发的我们,熟练使用 ADB 命令将会大大提升我们的开发效率, ADB 的命令 ...
- JSP自定义标记
JSP自定义标记(可以使JSP网页变得简洁并且易于维护) 一.自定义标记的方式 1.实现接口Tag 2.继承类TagSupport或BodyTagSupport 二.JSP自定义标记的生命周期 1 ...
- SpringBoot学习13:springboot异常处理方式3(使用@ControllerAdvice+@ExceptionHandle注解)
问题:使用@ExceptionHandle注解需要在每一个controller代码里面都添加异常处理,会咋成代码冗余 解决方法:新建一个全局异常处理类,添加@ControllerAdvice注解即可 ...
- ionic 命令cordova
安装android platform : ionic platform add android 安装一维码cordova插件 :cordova plugin add https://github.co ...
- ssm整合-错误
[Err] 1005 - Can't create table 'imoocdb.ec_article' (errno: 150) 这个错误由外键约束引起的 java.lang.ClassCastEx ...
- MySQL5.6基于MHA方式高可用搭建
master 10.205.22.185 #MHA node slave1 10.205.22.186 #MHA node+MHA manager slave2 10.205.22.187 #MH ...
- Tinyhttpd 知识点
1. fork 子进程 #include <stdio.h> #include <unistd.h> int main(void) { pid_t pid; ; pid = f ...
- git分布式版本控制系统常用的操作
Git是一个版本控制系统,用来追踪计算机文件的变化的工具,也是一个供多人使用的协同工具.它是一个分布式的版本控制系统,本文将简单介绍如何使用.简单来说,就是你要和你的伙伴一起完成一项任务,但是你们要互 ...
- python之微信好友统计信息
需要安装库:wxpy 代码如下: from wxpy import Bot,Tuling,embed,ensure_one bot = Bot(cache_path=True) #获取好友信息 bot ...
- Python分布式爬虫抓取知乎用户信息并进行数据分析
在以前的文章中,我写过一篇使用selenium来模拟登录知乎的文章,然后在很长一段时间里都没有然后了... 不过在最近,我突然觉得,既然已经模拟登录到了知乎了,为什么不继续玩玩呢?所以就创了一个项目, ...