【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 ...
随机推荐
- normalization, standardization and regularization
Normalization Normalization refers to rescaling real valued numeric attributes into the range 0 and ...
- 解决使用git出现 The file will have its original line endings in your working directory
执行以下命令即可解决 git rm -r --cached . git config core.autocrlf false git add . . 代表当前目录
- C语言数据结构——第四章 串
四.串 4.1-串的基本概念 串的定义 串是由数字.字母或其他字符组成的有限序列,一般记为 StringName = “a[0]a[1]a[2]···a[i]···a[n-1]”(n>0,0&l ...
- ET框架之SceneChangeComponent
初始化事件 using ETModel; namespace ETHotfix { [Event(EventIdType.InitSceneStart)] public class InitScene ...
- 常见运算符_python
一.算数运算符a=2b=5c=8#加减乘除print(a+b,a-b,a*b,a/b)#取模,也就是余数print(b%a)#取整除print(b//a)#幂(次方)print(b**a) 二.比较运 ...
- python之文件复制
python文件复制操作. # -*- coding: utf-8 -*- import shutil import os # file_path = 'C:\\Users\\WT\\Desktop\ ...
- 移动端CSS重置
移动端 CSS Reset 该怎么写 为了应对各大浏览器厂商对浏览器默认样式的不统一处理,我们往往会进行一个 css reset 操作,由于没有标准而且受个人偏好影响,每个公司实现的都不尽相同.关于 ...
- IntelliJ IDEA 2017.3尚硅谷-----设置自动编译
- 1.学习一下Angularjs的promisee
1.首先来了解一下promisee: 在谈论Promise之前我们要了解一下一些额外的知识:我们知道JavaScript语言的执行环境是“单线程”,所谓单线程,就是一次只能够执行一个任务,如果有多个任 ...
- EVE-NG镜像模板资源占用统计
转:http://www.emulatedlab.com/forum.php?mod=viewthread&tid=432&extra=page%3D1 EVE Image fold ...