【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 ...
随机推荐
- LitElement(四)属性
1.概述 LitElement管理您声明的属性及其对应的属性.默认情况下,LitElement将: 确保在任何声明的属性更改时进行元素更新. 捕获已声明属性的实例值.在浏览器注册自定义元素定义之前设置 ...
- HTML备忘
a标签事件 a:link {color: #000000} /* 未访问的链接 */ a:visited {color: #d90a81} /* 已访问的链接 */ a:hover {color: # ...
- python 请求服务器的本质
不同路由请求不同内容 ''' 根据url中不同路径返回不同内容 ''' import socket sk=socket.socket() sk.bind(("127.0.0.1", ...
- 如何转proto
找到对应协议在对应proto中的片段(片段的子也要提取),提出来 放到适合proto文件中(逻辑 || 功能近似协议聚集地) 转换成proto.js 替换 || 增加原有js内容
- L2-3 名人堂与代金券
题解 这题的话,每一个人都要占一个排名,即使排名并列了. 对于最后一个排名来说,即使人数超过了指定的k,也要加入. 代码 #include <bits/stdc++.h> using na ...
- AcWing 827. 双链表
https://www.acwing.com/problem/content/829/ #include <iostream> using namespace std; ; int m; ...
- mini-batch是什么 以及dataloader的作用
mini-batch是什么 以及dataloader的作用 待办 我们在训练神经网络时,使用的是mini-batch(一次输入多张图片),所以我们在使用一个叫DataLoader的工具为我们将5000 ...
- java位移运算符|And&,操作二进制
在java中 逻辑运算符有四种:& , |, &&, || &: 如果第一个条件是fasle,还会判断第二个条件,只要有一个条件不满足,结果就返回false; ...
- 一文复习JSP内容
概念: JSP 全名为 Java Server Pages, 中文名叫 java 服务器页面, 其根 本是一个简化的 Servlet 设计, 它是由 Sun Microsystems 公司 倡导. 许 ...
- 一文懂SSM项目中的web.xml常用配置项
做web后端工程师,逃不过的web.xml,我们都知道配置这个文件是日常工作了,那么我们来把一些必须知道知识点梳理下. 我们把web项目启动的时候,首先加载的就是web.xml这个文件,只有这个文件所 ...