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

分析

用邻接表法建图,用ret数组储存零售商的信息,用深度优先搜索法,从0开始搜索,知道遇到叶子节点(即是零售商),期间用level来储存层级,每一层表示原始价格乘以(1+r%).

#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
const int inf=9999999;
vector<int> G[100001];
int visited[100001]={0},ret[100001]={0},n,level=-1;
double p,r,sale=0;
void dfs(int root){level++;visited[root]=1;if(G[root].size()==0){sale+=p*pow(1+0.01*r,level)*ret[root];level--;return ;}for(int i=0;i<G[root].size();i++)if(visited[G[root][i]]==0)dfs(G[root][i]);level--;
}
int main(){cin>>n>>p>>r;for(int i=0;i<n;i++){int num,u;cin>>num;if(num!=0){for(int j=0;j<num;j++){cin>>u;G[i].push_back(u);}}else{cin>>u;ret[i]=u;}   }dfs(0);printf("%.1lf",sale);return 0;
}

转载于:https://www.cnblogs.com/A-Little-Nut/p/8403673.html

PAT 1079. Total Sales of Supply Chain相关推荐

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

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

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

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

  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 (25 分)

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

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

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

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

    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甲级1106 Lowest Price in Supply Chain:[C++题解]树、结点到根结点的距离、树形dp、记忆化搜索

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:这道题是第三次做了. 和PAT甲级1079 Total Sales of Supply Chain:[C++题解] 树.结点到根结点的 ...

最新文章

  1. poj 2247 Humble Numbers
  2. [YTU]_2621(B 继承 圆到圆柱体)
  3. 微信验证服务器是怎么回事,微信服务器认证为什么需要这么多参数?
  4. 【解析】案例4-1.5 顺序存储的二叉树的最近公共祖先问题
  5. Mybatis源码:Cache 装饰器模式
  6. mysql数据库优化清理_mysql 数据库优化整理
  7. 家里无线网络每天不定时段出现网速很慢或者直接无连接,这是怎么回事?
  8. 分布式系统的数据一致性问题
  9. 【易实战】Spring Cloud Greenwich Hystrix:服务容错保护
  10. 各省份国内、入境旅游人数 (2007-2018年)
  11. c语言顺序比较法字符,常用C语言排序算法解析
  12. 清华EMBA课程系列思考之九 -- 中国经济前沿问题解读
  13. 性能、应用、安装,选择LoRaWAN温湿度传感器的关键
  14. c语言date用法,c语言getdate()和gettime()的用法
  15. 微信 css3动画失效,css3 动画效果在微信中无效
  16. 支付宝授权登录免费源码奉献
  17. 跨境电商如何解决供应链物流效率、交付等重点问题
  18. 暴力破解zip压缩包
  19. 基于Java毕业设计宠物领养管理系统源码+系统+mysql+lw文档+部署软件
  20. 电动力学专题:电磁波传播时的色散效应

热门文章

  1. super函数没有那么简单-super原理剖析
  2. .net MVC4.0项目发布到阿里云虚拟主机中遇到的问题。
  3. 支撑计算机高速化的半导体技术
  4. 向webServices请求失败
  5. u-boot移植第五弹——2013.10u-boot通过tftp下载到内存中运行
  6. 一、Nginx常见问题
  7. 蓝牙模块怎么指定查询另一个蓝牙模块_蓝牙模块以IPEX端口外接天线、PCB板载天线最为常见...
  8. STL之bitset
  9. 这家创新学校是如何用钉钉宜搭构建了数字化管理网络的?
  10. 同样是查询语言,它和 SQL 竟然有这么多不同