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 ;
}

PAT_A1079#Total Sales of Supply Chain的更多相关文章

  1. PAT1079 :Total Sales of Supply Chain

    1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

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

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

  3. pat1079. Total Sales of Supply Chain (25)

    1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  4. 1079. Total Sales of Supply Chain (25)【树+搜索】——PAT (Advanced Level) Practise

    题目信息 1079. Total Sales of Supply Chain (25) 时间限制250 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is ...

  5. PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)

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

  6. 1079 Total Sales of Supply Chain ——PAT甲级真题

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

  7. PAT-1079 Total Sales of Supply Chain (树的遍历)

    1079. Total Sales of Supply A supply chain is a network of retailers(零售商), distributors(经销商), and su ...

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

    时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  9. 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

随机推荐

  1. 数据结构和算法设计专题之---二分查找(Java版)

    1.前提:二分查找的前提是需要查找的数组必须是已排序的,我们这里的实现默认为升序 2.原理:将数组分为三部分,依次是中值(所谓的中值就是数组中间位置的那个值)前,中值,中值后:将要查找的值和数组的中值 ...

  2. 密码学之RSA基础

    预备数论知识 互质关系 如果两个正整数,除了1以外,没有其他公因子,那么就称这两个数是互质关系 比如:4和7,13和61 欧拉函数 思考:任意给定整数n,在小于等于n的正整数中,有多少个数与n构成互质 ...

  3. [bzoj2729][HNOI2012]排队 题解 (排列组合 高精)

    Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...

  4. flutter 使用keyboard_actions 关闭ios键盘

    项目中登录 输入账号密码 弹出的键盘 关闭不了,从而 引来一些问题, 1,第一次关闭 项目是在 最外层包裹一层,点击的时候进行关闭, return Scaffold( resizeToAvoidBot ...

  5. eclipse中svn的各种图标详解

    参考:http://blog.sina.com.cn/s/blog_637810b101018xw0.html - 已忽略版本控制的文件.可以通过Window → Preferences → Team ...

  6. (转)openfire插件开发(三)通过http方式向openfire客户端发信息

    转:http://blog.csdn.net/hzaccp3/article/details/19964655 需求:  通过http方式,向openfire客户端发信息(非XMPP协议)openfi ...

  7. angularjs 中实现 load more 功能

    在UI 我们经常需要render 一些集合, 如果集合数据过多,那我们可能会采取分页的解决方案,本文是另外一种解决方法,就是当集合数量大于一定数量的时候显示一个 加载更多按钮,点击后,自动加载指定数量 ...

  8. CSS:CSS 创建

    ylbtech-CSS:CSS 创建 1.返回顶部 1. CSS 创建 当读到一个样式表时,浏览器会根据它来格式化 HTML 文档. 如何插入样式表 插入样式表的方法有三种: 外部样式表(Extern ...

  9. 1.1 React 介绍

    1.1.1 React 是什么 React IS A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES 来自:React 官方网站 狭义来讲 React ...

  10. Nginx 配置参数

    1 Proxy_send_timeout 定义后端在多久的时间内必须返回完所有的数据给Nginx. 2 Proxy_read_timeout