PAT 甲级 1079 Total Sales of Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.
Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. Only the retailers will face the customers. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.
Now given a supply chain, you are supposed to tell the total sales from all the retailers.
Input Specification:
Each input file contains one test case. For each case, the first line contains three positive numbers: N (≤), the total number of the members in the supply chain (and hence their ID's are numbered from 0 to N−1, and the root supplier's ID is 0); P, the unit price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:
Ki ID[1] ID[2] ... ID[Ki]
where in the i-th line, Ki is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj being 0 means that the j-th member is a retailer, then instead the total amount of the product will be given after Kj. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in one line the total sales we can expect from all the retailers, accurate up to 1 decimal place. It is guaranteed that the number will not exceed 1.
Sample Input:
10 1.80 1.00
3 2 3 5
1 9
1 4
1 7
0 7
2 6 1
1 8
0 9
0 4
0 3
Sample Output:
42.4
代码:
#include <bits/stdc++.h>
using namespace std; struct node {
double data;
vector<int> child;
}; vector<node> v;
double ans = 0.0, p, r; void dfs(int index, int depth) {
if(v[index].child.size() == 0) {
ans += v[index].data * pow(1 + r, depth);
return ;
}
for(int i = 0; i < v[index].child.size(); i++)
dfs(v[index].child[i], depth + 1);
}
int main() {
int n, k, c;
scanf("%d %lf %lf", &n, &p, &r);
r = r / 100;
v.resize(n);
for(int i = 0; i < n; i++) {
scanf("%d", &k);
if(k == 0) {
scanf("%lf", &v[i].data);
} else {
for(int j = 0; j < k; j++) {
scanf("%d", &c);
v[i].child.push_back(c);
}
}
}
dfs(0, 0);
printf("%.1f", ans * p);
return 0;
}
用 vector 写就超时 气气 渐渐失去希望
PAT 甲级 1079 Total Sales of Supply Chain的更多相关文章
- 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甲级——A1079 Total Sales of Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 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 ——PAT甲级真题
1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...
- PAT 1079 Total Sales of Supply Chain[比较]
1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...
- 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
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 ...
随机推荐
- oracle 数据库 NLS_CHARACTERSET 字符集的修改
修改Oracle 数据库字符集总结:修改方式大约有3种:方法一: (最安全的方法)数据库创建以后,如果需要修改字符集,通常需要重建数据库,通过导入导出的方式来转换.方法二: (最常用的方法)通过 &q ...
- PAT B1017 A除以B (20 分)
本题要求计算 /,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数.你需要输出商数 Q 和余数 R,使得 A=B×Q+R成立. 输入格式: 输入在一行中依次给出 A 和 B,中间以 1 ...
- laytpl js模板引擎
laytpl js模板引擎.laytpl是一款非常轻量的JavaScript模板引擎.地址:http://www.layui.com/laytpl/ 用法与handlebar.js类似,但是比较轻量级 ...
- Jmeter—开篇
Jmeter以开源.轻便著称,做接口测试.性能测试都可以借助Jmeter,从这篇开始记录我使用到的Jmeter功能. 安装 Jmeter官网:http://jmeter.apache.org/ 去官网 ...
- OpenGL笔记(二) 渲染管线
GLSL着色器代码分为两个部分,即Vertex Shader(顶点着色器)与Fragment Shader(片元着色器). 上下文环境搭建 OGL不负责窗口管理与上下文环境管理,该职责由平台完成.在A ...
- 电信3G上网卡自己主动重拨
须要使用电信3G无线上网卡做一个測试,由于要长时间使用,在使用的过程中老掉线,所以做了一个自己主动重连的批处理,好了,闲话少叙,开工: 先建立一个拨号连接: 001.png watermark/2/t ...
- java中CyclicBarrier简单入门使用
一个同步辅助类,它同意一组线程互相等待,直到到达某个公共屏障点 (common barrier point). 在涉及一组固定大小的线程的程序中,这些线程必须不时地互相等待.此时 CyclicBarr ...
- Struts2_learning
一.这是我学习struts2所做的一个记录,因为整个过程较为麻烦,所以,记录下来,以便以后使用 过程: 步骤: 1)dynamic web project 2)jars 3)struts.xml pa ...
- redis系列--深入哨兵集群
一.前言 在之前的系列文章中介绍了redis的入门.持久化以及复制功能,如果不了解请移步至redis系列进行阅读,当然我也是抱着学习的知识分享,如果有什么问题欢迎指正,也欢迎大家转载.而本次将介绍哨兵 ...
- 20155216 实验一 逆向与Bof基础
实验一 逆向与Bof基础 一.直接修改程序机器指令,改变程序执行流程 使用 objdump -d pwn1 对pwn1文件进行反汇编. 可知main函数跳转至foo函数,先要使main函数跳转至get ...