【PAT甲级】1079 Total Sales of Supply Chain (25 分)
题意:
输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比。接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结点接着输入一个整数表示该零售商进货的数量,X不为零则接着输入X个正整数表示它的下级经销商是哪些结点。输出所有零售商进货的总价。(结点从0~N-1,0为根节点即供应商)
AAAAAccepted code:
#include<bits/stdc++.h>
using namespace std;
int a[],lv[],ans[];
vector<int>v[];
void dfs(int x){
for(int it=;it<v[x].size();++it){
lv[v[x][it]]=lv[x]+;
dfs(v[x][it]);
}
}
int main(){
int n;
cin>>n;
double p,r;
cin>>p>>r;
int cnt=;
for(int i=;i<n;++i){
int x,num;
cin>>x;
if(!x){
cin>>num;
a[i]=num;
ans[++cnt]=i;
}
for(int j=;j<=x;++j){
cin>>num;
v[i].push_back(num);
}
}
dfs();
double sum=;
for(int i=;i<=cnt;++i){
double tamp=1.0*a[ans[i]]*p*pow(1.0+0.01*r,lv[ans[i]]);
sum+=tamp;
}
printf("%.1lf",sum);
return ;
}
【PAT甲级】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 ...
- PAT 甲级 1079 Total Sales of Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560 A supply chain is a ne ...
- 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)【树+搜索】——PAT (Advanced Level) Practise
题目信息 1079. Total Sales of Supply Chain (25) 时间限制250 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is ...
- 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点
和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...
- PAT甲级——A1079 Total Sales of Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 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) 1079. Total Sales of Supply Chain (25)
树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
随机推荐
- redis 的安装和使用
一.套用别人的话: redis 很牛叉,能将不同类型的数据存到内存,存到内存取出的时候就快了.所以,他很受欢迎.还有一个很牛叉的叫memcache ,但是他存的数据类型很有限,只能存入string 类 ...
- TWF
design seq1_b3 sta_label 0.0-1.0 0.0-1.0 1e-9 # clocks# clockID clock_name period rise_edge fall_edg ...
- 一个仿tp5分页组件的实现
样式: a{ text-decoration: none; color: inherit; } .out-cp{ width:100%; text-align: center; } .c-page{ ...
- 初识Vue--生命周期
初学Vue,写一些随记谨防忘记,不足之处谢谢指出!!! 本文可以直接复制自行创建一个HTML页面,查看结果. <!DOCTYPE html> <html lang="en& ...
- (GHRD)HPS
DE1作为ARM+FPGA的组合,ARM和FPGA之间通信,两个区块间有三个通道可以让两部分实现传输数据,统称为 HPS-FPGA AXI Bridges. 分别为:FPGA-to-HPS Bridg ...
- jvm(6):JMM
typora-root-url: ./ CPU多核并发缓存架构 JMM(Java线程内存模型)底层实现原理 基于CPU缓存模型建立的,屏蔽掉了底层不同计算机的区别. 所有的共享变量都存储在主内存.每条 ...
- PHP 源码 — intval 函数源码分析
PHP 源码 - intval 函数源码分析 文章来源: https://github.com/suhanyujie/learn-computer/ 作者:suhanyujie 基于PHP 7.3.3 ...
- [前端] html限制input输入数字和小数
限制input只能输入数字和小数 html代码 <input type="text" style="width:50px" name="widt ...
- Flink读写Kafka
Flink 读写Kafka 在Flink中,我们分别用Source Connectors代表连接数据源的连接器,用Sink Connector代表连接数据输出的连接器.下面我们介绍一下Flink中用于 ...
- ajax异步获取请求,获得json数组后对数组的遍历
如果响应数据是以html的形式发出来的,即 response.setContentType("text/html;charset=utf-8"); 那么一般用下面这种方式,但是要注 ...