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

 #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的更多相关文章

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

  2. PAT 甲级 1079 Total Sales of Supply Chain

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

  3. A1079. Total Sales of Supply Chain

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

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

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

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

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

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

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

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

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

  9. PAT1079 :Total Sales of Supply Chain

    1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

随机推荐

  1. Docker学习のDocker的简单应用

    一.常见基本docker命令 docker是在一个linux虚拟机上运行的(对于windows来说),打开Docker quickStart terminal,就连街上了docker的 daemon ...

  2. springboot 简单搭建(thymeleaf 视图显示)

    接口访问参考:https://blog.csdn.net/hanjun0612/article/details/81625395 PS:调用接口和跳转网页 主要区别是 1 调用接口是 @RestCon ...

  3. innodb 表

    1.innodb的存储引擎表类型 如果在创建表时没有显示的定义主键,则innodb存储引擎会按如下方式选择或创建主键 a.首先表中是否有非空的唯一约束(Unique not null)如果有,则该列即 ...

  4. IDEA快捷键(收集自网络后整理)

    快捷键 说明 CTRL+B 快速打开光标处的类或方法 CTRL+C 拷贝 CTRL+D 复制当前行到下一行 CTRL+E 最近打开的文件 CTRL+F 当前文件查找特定内容 CTRL+G 定位行 CT ...

  5. Delphi 查找标题已知的窗口句柄,遍历窗口控件句柄

    有了回调函数的概念及上面的例子,我们可以继续了.其实想要找到一个标题已知的窗口句柄,用一个API函数就可以了:FindWindow.其函数原形是:function FindWindow(lpClass ...

  6. python使用PIL处理图片后返回给前端的坑

    一.python代码 这里有个坑,之前没有将bytes图片数据转成base64就返回到前端了,但在前端处理的时候,怎么都显示不出图片来,虽然数据拿到了,但bytes被传到前后变str了,所以怎么搞都没 ...

  7. react 高阶组件之小学版

    高阶组件  多么高大上的概念,一般用来实现组件逻辑的抽象和复用,在很多三方库(redux)中都被使用到,但是开发普通有任务项目时,如果能合理使用高阶组件,也会显著的提高代码质量. 我们今天就用最简单的 ...

  8. 关于Async与Await的FAQ

    =============C#.Net 篇目录============== 环境:VS2012(尽管System.Threading.Tasks在.net4.0就引入,在.net4.5中为其增加了更丰 ...

  9. 盒子阴影 box-shadow

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. range()函数在python3与python2中的区别

    range()函数在python3与python2中的区别 - CSDN博客 https://blog.csdn.net/weixin_37579123/article/details/8098038 ...