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 (<=105), 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 1010.

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<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = 100010;struct node{double data;vector<int> child;
}Node[maxn];
int n;
double p,r,ans = 0;void DFS(int index,int depth){if(Node[index].child.size() == 0){//    printf("yezi %.lf\n",Node[index].data);// 验证 ans += Node[index].data * pow(1 + r, depth);return;}for(int i = 0; i < Node[index].child.size(); i++){//    printf("jiedian %d\n",Node[index].child[i]); //验证 aDFS(Node[index].child[i],depth+1);}
}
int main(){scanf("%d%lf%lf",&n,&p,&r);r /= 100;int k,child;for(int i = 0; i < n; i++){scanf("%d",&k);if(k == 0) scanf("%lf",&Node[i].data); //零售商的货物else{for(int j = 0; j < k; j++){scanf("%d",&child);Node[i].child.push_back(child);}}     }DFS(0,0); printf("%.1f",p * ans);
} 

转载于:https://www.cnblogs.com/wanghao-boke/p/8572097.html

1079. Total Sales of Supply Chain (25)相关推荐

  1. PAT甲级 -- 1079 Total Sales of Supply Chain (25 分)

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

  2. 1079. Total Sales of Supply Chain (25)-PAT甲级真题(dfs,bfs,树的遍历)

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

  3. 1079 Total Sales of Supply Chain(甲级)

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

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

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

  5. PAT甲级1079 Total Sales of Supply Chain:[C++题解] 树、结点到根结点的距离、树形dp、记忆化搜索

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:下图是对样例的模拟图示,题目就是统计叶子结点卖出去的钱数.根据下图,我们第一步是建树,第二步是统计叶子结点到根结点的距离,然后才能知道 ...

  6. PAT 1079. Total Sales of Supply Chain

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

  7. 1079 Total Sales of Supply Chain

    1. 这道题考察的是树的层次遍历,结点需要有层这个属性,对于我来说,难点在于什么时候给层赋值,看书后知道应该是在加入队列之前(不管是根节点还是之后所有节点). 2. 一开始算得216,原因是把r直接加 ...

  8. 【PAT】A1079 Total Sales of Supply Chain

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

  9. PAT甲级 -- 1090 Highest Price in Supply Chain (25 分)

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

最新文章

  1. 【练习题】构造方法 编写Java程序,模拟简单的计算器。
  2. AtomicInteger相关类
  3. 经典面试题(30):以下代码将输出的结果是什么?
  4. Spring Spring MVC Hibernate 整合备忘
  5. 字符串型的数字相加减_【每日编程158期】罗马数字转整数
  6. 让ie8按照ie7 的方式来进行解析
  7. IOS和Android测试分别有什么侧重点?
  8. python字符串split()函数
  9. 同步异步和阻塞3-同步阻塞
  10. Unity渐进式GPU烘焙找不到显卡
  11. 485芯片方向切换的几种方式及原理
  12. 计算机水印如何操作,图片的水印如何添加|怎么用word给图片添加水印
  13. 见缝插针的人_“见缝插针”的创意人生
  14. 平面多边形凹凸判断(叉乘法)
  15. 《Gossip Girl》情侣布莱克·莱弗利(Blake Lively) 和佩恩·贝格利(Penn Badgley)分手
  16. 通过阿里P9代考这件事,聊聊职级
  17. 2 机器学习入门——逻辑回归之kaggle泰坦尼克号竞赛
  18. nmap 扫描端口_Nmap端口规格和扫描顺序
  19. (股票,数字货币)年收益率,标准差和夏普率的计算
  20. 重载、重写(覆盖)、重定义(同名隐藏)的区别

热门文章

  1. axios 参数为payload的解决方法
  2. C++ namespace
  3. JAVA UDP网络编程学习笔记
  4. 空军军医大学计算机复试线,空军军医大学2019年考研复试分数线
  5. linux网络唤醒,如何在Ubuntu Server 18.04中启用网络唤醒(WOL)
  6. matlab期末复习资料,MATLAB期末复习习题及答案
  7. php如何与数据库连接,PHP文章如何和数据库连接(1)
  8. php连接mysql数据,php连接mysql数据库
  9. vs使用了未初始化的局部变量怎么解决_C程序为什么要初始化?
  10. 求10以内平均数的c语言,求助 给小学生出题,自己选加减乘除 做10题 10以内的数 然后统计分...