PAT甲级——A1079 Total Sales of Supply Chain
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 <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
int N;
double p, r, res = 0.0;
struct Node
{
int flag, w, l;
vector<int>next;
Node(int f = , int w = ) :flag(f), w(w) {}
};
int main()
{
cin >> N >> p >> r;
vector<Node*>v;//记录手下人
int k, a;
for (int i = ; i < N; ++i)
{
cin >> k;
if (k == )
{
Node* node = new Node();
cin >> node->w;
v.push_back(node);
}
else
{
Node* node = new Node();
for (int j = ; j < k; ++j)
{
cin >> a;
node->next.push_back(a);
}
v.push_back(node);
}
}
int level = ;
queue<Node*>q;
v[]->l = ;
q.push(v[]);
while (!q.empty())
{
Node* node = q.front();
q.pop();
if (node->flag == )//零售商
res += p * pow((1.0 + r / 100.0), node->l) * node->w;
else
{
for (auto t :node->next)
{
v[t]->l = node->l + ;
q.push(v[t]);
}
}
}
printf("%.1f\n", res);
return ;
}
PAT甲级——A1079 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 甲级 1079 Total Sales of Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560 A supply chain is a ne ...
- 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 ...
- PAT_A1079#Total Sales of Supply Chain
Source: PAT A1079 Total Sales of Supply Chain (25 分) Description: A supply chain is a network of ret ...
- 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 ...
- PAT1079 :Total Sales of Supply Chain
1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
随机推荐
- redhat7和redhat6混合搭建文档
1.下载cm对应redhat7的版本.2.修改/opt/cloudera/cm-5.10.0/etc/cloudera-scm-agent/config.ini成为中心机器hostname/ip(ma ...
- JS事件 卸载事件 当用户退出页面时(页面关闭、页面刷新等),触发onUnload事件,同时执行被调用的程序。注意:不同浏览器对onunload事件支持不同。
卸载事件(onunload) 当用户退出页面时(页面关闭.页面刷新等),触发onUnload事件,同时执行被调用的程序. 注意:不同浏览器对onunload事件支持不同. 如下代码,当退出页面时,弹出 ...
- TwainCapabilities
Twain Capabilities 2013年10月15日 ⁄ 综合 ⁄ 共 6098字 ⁄ 字号 小 中 大 ⁄ 评论关闭 转自:http://blog.163.com/lvan100@yeah/ ...
- Python学习笔记(三)——文件系统中的常用方法
OS模块中关于文件/目录常用的函数使用方法 函数名 使用方法 getcwd() 返回当前工作目录 chdir() 改变工作目录 listdir(path='.') 列举指定目录中的文件名('.'表示当 ...
- Android开发 View_自定义圆环进度条View
前言 一个实现,空心圆环的自定义View,已经封装完好,可以直接使用. 效果图 代码 import android.content.Context; import android.graphics.C ...
- AOP-面向切面编程-1
将方法类比成一个积木,哪里需要执行插到哪里 视野角度就是将一个程序比作几条绳子的集合,每个集合是一堆方法的集合,那么把绳子截断,绳子的切面就是一堆方法中一个方法与另一个方法的交界处,将你需要的方法切入 ...
- 能轻松背板子的FWT(快速沃尔什变换)
FWT应用 我不知道\(FWT\)的严格定义 百度百科和维基都不知道给一坨什么****东西** FWT(Fast Walsh Fransform),中文名快速沃尔什变换 然后我也不知道\(FWT\)到 ...
- https 生成秘钥
#生成一个RSA秘钥 openssl genrsa -des3 -out a_com.key 1024 #生成一个证书请求openssl req -new -key a_com.key -out a_ ...
- FTP、FTPS、SFTP概览
1. 基本概念 FTP:File Transfer Protocol FTPS:FTP over SSL.构建在SSL/TLS(Secure Socket Layer/Transport Layer ...
- 2019-9-23-asp-dotnet-core-3.0-接口返回-json-使用-PascalCase-格式
title author date CreateTime categories asp dotnet core 3.0 接口返回 json 使用 PascalCase 格式 lindexi 2019- ...