题目信息

1079. Total Sales of Supply Chain (25)

时间限制250 ms

内存限制65536 kB

代码长度限制16000 B

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:

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

解题思路

建树,搜索

AC代码

#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
int a[100005];
vector<int> level[100005];
int n, tn, t;
double p, r;
double dfs(int root, int lv){
double s = 0;
if (level[root].size() == 0){
s += a[root] * pow(1+r/100, lv) * p;
}
for (int i = 0; i < level[root].size(); ++i){
s += dfs(level[root][i], lv + 1);
}
return s;
}
int main()
{
scanf("%d%lf%lf", &n, &p, &r);
for (int i = 0; i < n; ++i){
scanf("%d", &tn);
if (tn > 0){
while (tn--){
scanf("%d", &t);
level[i].push_back(t);
}
}else{
scanf("%d", &t);
a[i] = t;
}
}
printf("%.1f\n", dfs(0, 0));
return 0;
}

1079. Total Sales of Supply Chain (25)【树+搜索】——PAT (Advanced Level) Practise的更多相关文章

  1. 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 ...

  2. 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点

    和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...

  3. PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...

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

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

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

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

  6. PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)

    树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  7. 【PAT甲级】1079 Total Sales of Supply Chain (25 分)

    题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...

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

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

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

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

随机推荐

  1. spark作业

    假定用户有某个周末网民网购停留时间的日志文本,基于某些业务要求,要求开发 Spark应用程序实现如下功能: 1.实时统计连续网购时间超过半个小时的女性网民信息. 2.周末两天的日志文件第一列为姓名,第 ...

  2. cinema 4d 包括宝典 --- 改线 循环边 建模布线原则

    cinema 4d 一.视图控制与物体控制 1.摇移      alt+鼠标左键   转圈看物体  改变角度 2.平移  alt +鼠标中键      不改变角度  移动 3.推拉  alt+鼠标右键 ...

  3. BZOJ4316 小C的独立集 【仙人掌】

    题目 图论小王子小C经常虐菜,特别是在图论方面,经常把小D虐得很惨很惨. 这不,小C让小D去求一个无向图的最大独立集,通俗地讲就是:在无向图中选出若干个点,这些点互相没有边连接,并使取出的点尽量多. ...

  4. ACE的饼图显示保留两位小数

    修改源js文件:jquery.flot.pie.min.js <script src="/static/assets/js/jquery.flot.pie.min.js"&g ...

  5. Unity 过度光照贴图

    背景:开关窗帘过程,让环境在亮和暗之间过度 事先烘培出亮.暗两张Lighting map.然后代码实现,窗帘开关由动作实现,而代码中通过动作执行进度来过度两张Lighting map void OnA ...

  6. 加速和简化构建Docker(基于Google jib)

    赵安家 2019年02月11日阅读 1518 关注 加速和简化构建Docker(基于Google jib) 介绍 其实jib刚发布时就有关注,但是一直没有用于生产,原因有二 基于 spotify/do ...

  7. 如何选择IO流

    1)确定是数据源和数据目的(输入还是输出) 源:输入流 InputStream Reader 目的:输出流 OutputStream Writer 2)明确操作的数据对象是否是纯文本 是:字符流Rea ...

  8. [LeetCode] Edit Distance 字符串变换为另一字符串动态规划

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  9. upper_bound()和lower_bound()

    ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, la ...

  10. Linux命令文件查看过滤

    Linux命令篇 1.查看一个文件的后100行的命令: tail -n 100 Linux下查看文件前几行一般用head -n xx,查看后面几行用tail -n xx.除此之外,还有: tail - ...