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. 区间dp+预处理——cf1278F(难题)

    感觉很难的区间dp,主要是状态难想 /* 对于一个区间[i,j],设其最小的颜色编号是c=Min[i,j],那么该区间显然有一大段是以c为底的 设这个颜色在该区间出现位置的两端是L[c],R[c],那 ...

  2. 从客户端中检测到有潜在危险的 request.form值 以及 request.querystring[解决方法]

    一.从客户端中检测到有潜在危险的request.form值 当页面编辑或运行提交时,出现“从客户端中检测到有潜在危险的request.form值”问题,该怎么办呢?如下图所示: 下面博主汇总出现这种错 ...

  3. 技巧&注意事项合集

    技巧&注意事项合集 杂项 OI Wiki有很多实用的东西 编程环境 打开Dev-C++中工具-编译选项-代码生成/优化-代码警告-显示最多警告信息的开关,可以检查出一堆傻逼错误 define ...

  4. Django框架(二)—— 基本配置:app注册、模板配置、静态文件配置、数据库连接配置post和get

    目录 app注册.模板配置.静态文件配置.数据库连接配置post和get 一.app 二.模板配置 三.静态文件配置 四.数据库连接配置 五.get请求和post请求 六.新手三件套 七.登录功能案例 ...

  5. CUDA编程之环境配置

    VS2015+CUDA8.0环境配置 Anyway,在这里记录下正确的配置方式: 1.首先,上官网下载对应vs版本的CUDA toolkit: https://developer.nvidia.com ...

  6. java 8 bug

    jpa保存实体的时候,不能用{{}}初始化对象,否则会报异常 org.springframework.dao.InvalidDataAccessApiUsageException: Unknown e ...

  7. javascript 学习犯错记录

    看w3c学习js,有时按自己想法来,会出一些莫名奇妙的错误,而这些问题百度到了,但因为学习原因基础不捞,导致看到了答案,却认为这不是答案 1.一个很简单的 一个html,一个js文件 我想在js中的b ...

  8. <人工智能>人工智能基础

    问题1:扔下圆球的位置(feature特征变量)变化,最终掉落奖项(label结果标签)的变化 feature ----输入 f(x) ----模型,算法 label ----输出 大量已知的数据,训 ...

  9. D2D

    layout category title permalink posts_by_category D2D 渲染相关 /post/D2D.html

  10. java访问https绕过证书信任

    package com.xing.test; import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...