【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 ...
随机推荐
- C#中画三角形和填充三角形的简单实现
C#中画三角形和填充三角形的简单实现: private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graph ...
- mysq,oraclel复杂SQL操作汇总
一.对数据库原有字段默认值的设置 1.删除原有字段默认值 alter table 表名 alter column 字段 drop default;2..重写原有字段默认值alter table 表名 ...
- css 页面滚动 多背景固定不动
经常看到一些网站,滚动页面但是背景图不会跟着滚动,好像一直固定在浏览器窗口,感觉挺酷的,哇哦 ~ ~ 原来都是 background-attachment 这位大兄弟的功劳 background-at ...
- C#中ESRI.ArcGIS.esriSystem的引用问题
ESRI.ArcGIS.esriSystem,在引用里没有它的同名引用,其实它对应的引用为ESRI.ArcGIS.System,所以添加“ESRI.ArcGIS.System”这个引用即可
- centOS7中启动MySQL数据库提示: Failed to start mysqld.service: Unit not foundc
现象: 在centOS7中启动MySQL数据库提示: Failed to start mysqld.service: Unit not found [明明已经安装了,为什么提示不存在呢?] 原因: 在 ...
- 今天我解决的sql中文乱码问题
昨天我终于把我的网站做好了,在电脑上准备就绪,经过测试一切正常,放上服务器上准备炫耀一下的时候,发现插进数据库的中文字段全都变成???了,检测了下,前台是utf-8,后台是utf-8,在插进数据库前我 ...
- 常见css属性
div { width: 100px; height: 100px; /* 表示行高 */ line-heigh ...
- (转)Java中的String与常量池
Java中的String与常量池 转自:http://developer.51cto.com/art/201106/266454.htm string是java中的字符串.String类是不可变的,对 ...
- Hibernate知识点整理
一, Hibernate 介绍: Hibernate 只是一个将持久化类与数据库表相映射的工具,每个持久化类实例均对应于数据库表中的一个数据行而已.用户只需直接使用面向对象的方法操作此持久化类实例,即 ...
- css的理解 ----footrt固定在底部
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...