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:

K​i​​ ID[1] ID[2] ... ID[K​i​​]

where in the i-th line, K​i​​ 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. K​j​​ being 0 means that the j-th member is a retailer, then instead the total amount of the product will be given after K​j​​. 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

题意:

  第三次见到类似的题目了

思路:

  用path[]储存该节点的上一个节点,以此来找到root,从而确定中间一共涨价几次,然后再将涨价后的价格与数量相乘,最后求和即可。(但是这样最后一组数据会超时)

Code:

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
double p, r;
cin >> n >> p >> r;
vector<int> path(n);
vector<pair<int, int> > product;
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
if (k == 0) {
int t;
cin >> t;
product.push_back({i, t});
} else
for (int j = 0; j < k; ++j) {
int t;
cin >> t;
path[t] = i;
}
}
double sum = 0.0;
for (int i = 0; i < product.size(); ++i) {
int id = product[i].first;
int count = 0;
while (id != 0) {
id = path[id];
count++;
}
sum += (pow(1 + r / 100.0, count) * p) * product[i].second;
} cout << fixed << setprecision(1) << sum << endl; return 0;
}

看了一下别人的代码发现使用DFS来做的。

1079 Total Sales of Supply Chain的更多相关文章

  1. PAT 1079 Total Sales of Supply Chain[比较]

    1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...

  2. 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 ...

  3. 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 ...

  4. 1079 Total Sales of Supply Chain ——PAT甲级真题

    1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...

  5. 1079. Total Sales of Supply Chain (25)

    时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  6. 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  7. PAT 甲级 1079 Total Sales of Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560 A supply chain is a ne ...

  8. 1079 Total Sales of Supply Chain (25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. PAT 1079. Total Sales of Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  10. PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...

随机推荐

  1. docker 上传到docker hub 采坑

    前面是仓库名称 后面可以命名img名字 docker push gaodi2345/wj:docker_gui

  2. C#实现JWT无状态验证的实战应用

    前言 本文主要介绍JWT的实战运用. 准备工作 首先我们创建一个Asp.Net的,包含MVC和WebApi的Web项目. 然后使用Nuget搜索JWT,安装JWT类库,如下图. 设计思路 这里我们简单 ...

  3. 9.Vue之webpack打包基础---模块化思维

    主要内容: 1. 什么是模块化思维? 2.  ES6包的封装思想 一.什么是模块化思维呢? 现实工作中, 一个项目可能会有多个人同时开发. 然后, 将所有人开发的内容, 合并到一个文件中. 比如: 1 ...

  4. Elasticsearch精进之路:elasticsearch-head插件使用教程

    一.elasticsearch-head插件的作用 ealsticsearch是一个分布式.RESTful 风格的搜索和数据分析引擎,所有的数据都是后台服务存储着,类似于Mysql服务器,因此如果我们 ...

  5. OpenGL光照贴图

    一:啥叫贴图 上一节中,我们将整个物体的材质定义为一个整体,但现实世界中的物体通常并不只包含有一种材质,而是由多种材质所组成. 拓展之前的系统,引入漫反射和镜面光贴图(Map).这允许我们对物体的漫反 ...

  6. SpringMVC-04 数据处理及跳转

    SpringMVC-04 数据处理及跳转 结果跳转方式 1.ModelAndView 设置ModelAndView对象 , 根据view的名称 , 和视图解析器跳到指定的页面 . 页面 : {视图解析 ...

  7. BeetleX使用bootstrap5开发SPA应用

        在早期版本BeetleX.WebFamily只提供了vuejs+element的集成,由于element只适合PC管理应用开发相对于移动应用适配则没这么方便.在新版本组件集成了bootstra ...

  8. 「CTSC 2013」组合子逻辑

    Tag 堆,贪心 Description 给出一个数列 \(n\) 个数,一开始有一个括号包含 \([1,n]\),你需要加一些括号,使得每个括号(包括一开始的)所包含的元素个数 \(\leq\) 这 ...

  9. 安装VMTools失败的三类解决方法(Windows、Linux、MacOs)

    前言 写这篇笔记的原因,是前几天在虚拟机 Vmware 中重新安装了几个操作系统,突然发现 VMTools 这个工具成了一个特殊的问题,以前还没有发现,因为通常它就给你自动安装了.但是大多数时候也是需 ...

  10. SpringSecurity---基于内存的FormLogin

    SpringSecurity已经内置了一个登陆页面,所以目前我们就采取默认的登陆页面 一. 引入依赖 这步略过不表 二. 默认实现 添加接口 @RestController public class ...