Source:

PAT A1079 Total Sales of Supply Chain (25 分)

Description:

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 Pand 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

Keys:

Code:

 /*
time: 2019-03-30 18:34:12
problem: PAT_A1079#Total Sales of Supply Chain
AC: 12:50 题目大意:
根结点价格为p,各层溢价r%,计算所有叶子结点的价格(单价*数量)
输入:
第一行给出:结点数N,p,r
接下来N行,孩子结点数,孩子编号(0~N-1,root==0);若孩子数为0,则给出销售数量 基本思路:
遍历统计叶子结点的深度并计算价格即可
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int M=1e5+;
vector<int> tree[M];
int sell[M]={};
double total=,p,r; void Travel(int root, int hight)
{
if(tree[root].size() == )
{
total += p*pow((0.01*r+),hight)*sell[root];
return;
}
for(int i=; i<tree[root].size(); i++)
Travel(tree[root][i],hight+);
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,k,kid;
scanf("%d%lf%lf", &n,&p,&r);
for(int i=; i<n; i++)
{
scanf("%d", &k);
if(k==)
{
scanf("%d", &kid);
sell[i]=kid;
}
for(int j=; j<k; j++)
{
scanf("%d", &kid);
tree[i].push_back(kid);
}
}
Travel(,);
printf("%.1f", total); return ;
}

最新文章

  1. java实现敏感词过滤(DFA算法)
  2. 非旋treap模板
  3. Web jquery表格组件 JQGrid 的使用 - 全部代码
  4. RAID-4与模2和
  5. HashSet 读后感
  6. Xcode8适配iOS10.1真机测试
  7. angularjs使用directive实现分页组件
  8. Demon_Tank (坦克移动发射子弹)
  9. linux修改系统时间
  10. 将一个实体转换成 Url 参数的形式 ?a=a&amp;b=b
  11. sqoop1.4.6导出oracle实例
  12. Django之Model进阶的更多操作
  13. POJ-2955 Brackets(括号匹配问题)
  14. CreateEvent
  15. dblinks
  16. JavaScript:动态代理之远程代理
  17. Spring官方文档翻译(1~6章)
  18. IdentityServer4揭秘---登录
  19. 使用go写一个简单的exe文件
  20. BZOJ 4945 NOI2017 游戏 搜索+2-SAT

热门文章

  1. 【LeetCode 20】有效的括号
  2. [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
  3. es6学习笔记--箭头函数
  4. jq鼠标移入和移出事件
  5. thinkphp5操作redis系列教程】列表类型之lRange,lGetRange
  6. lamp+nginx代理+discuz+wordpress+phpmyadmin搭建
  7. 众所周知,static修饰的成员只实例化一次,而string类型每次赋值都会重新创建一个实例,那么用static修饰string呢?
  8. python--常用模块:collections 、time、random
  9. JS变量1
  10. D2D