1079 Total Sales of Supply Chain (25 分)

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 (≤10​5​​), 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 10​10​​.

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 <vector>
#include <algorithm>
#include <cmath>
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) {ans += Node[index].data * pow((1 + r), depth);return;}for (int i = 0; i < Node[index].child.size(); i++) {DFS(Node[index].child[i], depth + 1);}
}int main() {int k, child;scanf("%d%lf%lf", &n, &p, &r);r /= 100;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\n", p*ans);return 0;
}

1079 Total Sales of Supply Chain (25 分) 树的遍历:DFS+vector相关推荐

  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)

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

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

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

  4. 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[比较]

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

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

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

  7. PAT 1079. Total Sales of Supply Chain

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

  8. 1079 Total Sales of Supply Chain

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

  9. 【PAT】A1079 Total Sales of Supply Chain

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

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

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

最新文章

  1. matplotlib.pyplot中add_subplot方法参数的含义
  2. 为什么要低温保存_渔之歌科普课堂:冷冻食品为什么要规定零下18摄氏度冷藏?...
  3. 庖丁解“学生信息管理系统”
  4. java获取年初年末_Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间...
  5. (转)Apache的安装与配置
  6. WPF ---- ​xmal 解析器没有办法解析类的TypeConverter
  7. hihoCoder 1367 等式填空
  8. 横河川仪压力变送器故障代码_YOKOGAWA/重庆横河川仪EJA变送器三大优秀性能!
  9. mysql10.3修改默认存储路径
  10. python下载问题_初学者下载使用Python遇到的问题看它就行了
  11. 第十一届蓝桥杯大赛软件类省赛第二场 C/C++ 大学 B 组 附蓝桥杯官网网址
  12. armbian格式化磁盘命令,甜糖格式化磁盘
  13. 项目合同管理:合同分类、费用支付方式、违约责任承担方式、签订注意事项、合同索赔流程
  14. 字符串匹配算法 之 Aho-Corasick
  15. NOIP模拟 葫芦(分数规划)
  16. TCP/IP中的链路层
  17. 【Python】批量修改照片文件名为拍摄日期
  18. Go语言框架Gin之4 安全认证
  19. Android中读values/xml arrays attrs colors dimens string styles
  20. 整合SEO和UEO也许才是SEOer的出路

热门文章

  1. Easy machine learning pipelines with pipelearner: intro and call for contributors
  2. bzoj2697特技飞行*
  3. 最简单的TCP网络封包解包(补充)-序列化
  4. 爱与光 android4.0学习
  5. JSP 页面 嵌入 google API 地图
  6. Softether软件原理分析
  7. php 上标,PHP数组上标类型陷阱
  8. cv2 python 读取像素点_OpenCV+Python车牌字符分割和识别入门
  9. linux如何远程装java_使用Shell远程给Linux安装JDK
  10. hibernate java.util.date 精度_hibernate中java.util.Date类型映射