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

总结:

  1. 这是一道典型的树的遍历的图,与1053类似,没有遇到大的麻烦,代码格式DFS:设置边界——树的递归
  2. 链接:【2019暑假刷题笔记-树的遍历】1053 Path of Equal Weight

代码:

#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
const int maxn=100010;
int total,count,counter;
double price,r,sum=0;
struct Node{int data;vector<int> child;
}node[maxn];void DFS(int index,int depth){if(node[index].child.size()==0){sum += node[index].data*pow(1+r,depth); return;}for(int i=0;i<node[index].child.size();i++){  //这一步也很重要深度搜索的命脉 int child=node[index].child[i];DFS(child,depth+1); }} int main(){scanf("%d %lf %lf",&total,&price,&r);r /= 100;int v,child,data;count=0;for(int i=0;i<total;i++){scanf("%d",&v);if(v==0){scanf("%d",&data);node[i].data=data;count++;}for(int j=0;j<v;j++){scanf("%d",&child);node[i].child.push_back(child);}}DFS(0,0);//传入的参数有结点编号,深度printf("%.1lf\n",price*sum);return 0;
}

【PAT】A1079 Total Sales of Supply Chain相关推荐

  1. 【PAT】A1090 Highest Price in Supply Chain

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

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

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

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

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

  4. 【PAT】A1106 Lowest Price in Supply Chain

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

  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. 1079 Total Sales of Supply Chain(甲级)

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

  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 (25)-PAT甲级真题(dfs,bfs,树的遍历)

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

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

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

最新文章

  1. Java基础学习总结(23)——GUI编程
  2. leetCode:twoSum 两数之和 【JAVA实现】
  3. yolov5和yolov5-face nms比较
  4. Java 添加音频到ppt_Java 添加文本框到PPT幻灯片过程解析
  5. java 矩阵求逆_java实现的顺时针/逆时针打印矩阵操作示例
  6. 第四十期:2019年度十大Web开发趋势
  7. WIN 10 安装 Hadoop 2.7.7 + Spark 2.4.7 记录
  8. Java练习01 输出质数(素数) 使用及不使用标签Lable
  9. 马云:CFO 不能做 CEO;腾讯推短视频“哈皮”;三星中国份额跌至 2% | 极客头条...
  10. python变量图片_在Python中向3D图添加第4个变量
  11. Jzoj5662 尺树寸泓
  12. JAVA解压tar,可以使用javatar
  13. 2021年顶级服务器备份软件和解决方案
  14. 黑苹果OC的血泪史之硬盘(三星固态1T)篇
  15. 三星4k3d电视测试软件,三大硬性指标 揭开伪4K电视真实面目
  16. du命令排序文件大小
  17. CCNA学习-路由器交换机的管理配置
  18. rtl8812驱动分析(二)
  19. 【项目分享~写给应届生的一篇文章】基于Web电影院购票系统 ~~ 选座模块
  20. 双云台AI智能分析跟踪会议云台摄像机技术应用

热门文章

  1. 登陆共享服务器的位置,共享服务器哪里登陆
  2. Html 教程 (7)布局
  3. (chap6 Http首部) 请求首部字段 AuthorizationExpectFromHostIf-Match
  4. C++ Primer 5th笔记(chap 14 重载运算和类型转换)输入和输出运算符
  5. 【Flask】request请求
  6. 修改PE可选头关闭ASLR
  7. 2020-12-4((ARM汇编)mov指令,LDR指令,LDR伪指令)
  8. 016 Android之NDK开发
  9. 160个Crackme014
  10. MySQL的版本以及版本号