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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef struct NODE{
vector<int> child;
int depth;
int product;
}node;
node tree[];
int N;
double P, r; //需要把/100
double bfs(int root){
queue<int> Q;
double ans = ;
if(tree[root].child.size() != ){
Q.push(root);
tree[root].depth = ;
}else{
ans = tree[root].product * 1.0 * P;
}
while(Q.empty() == false){
int temp = Q.front();
Q.pop();
if(tree[temp].child.size() == ){
ans += (double)P * pow(1.0 + r, tree[temp].depth * 1.0) * 1.0 * tree[temp].product;
}
int len = tree[temp].child.size();
for(int i = ; i < len; i++){
tree[tree[temp].child[i]].depth = tree[temp].depth + ;
Q.push(tree[temp].child[i]);
}
}
return ans;
}
int main(){
int cnt;
scanf("%d %lf %lf", &N, &P, &r);
r = r / 100.0;
for(int i = ; i < N; i++){
scanf("%d", &cnt);
if(cnt != ){
for(int j = ; j < cnt; j++){
int tempc;
scanf("%d", &tempc);
tree[i].child.push_back(tempc);
}
}else{
scanf("%d", &tree[i].product);
}
}
double ans = bfs();
printf("%.1f", ans);
cin >> N;
return ;
}

总结:

1、货物从供应商开始层层加价,然后计算最终总货物的价格。其实就是求每个叶子节点的深度,然后计算价格即可。

2、注意当只有一个根节点时的情况单独处理。

3、pow(a, b)函数:计算a的b次幂,要求a与b都是小数。所以当计算小数次幂时使用pow,计算整数时自己写函数。

A1079. Total Sales of Supply Chain的更多相关文章

  1. PAT甲级——A1079 Total Sales of Supply Chain

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

  2. PAT_A1079#Total Sales of Supply Chain

    Source: PAT A1079 Total Sales of Supply Chain (25 分) Description: A supply chain is a network of ret ...

  3. PAT1079 :Total Sales of Supply Chain

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 【数据库】Mysql中主键的几种表设计组合的实际应用效果

    写在前面 前前后后忙忙碌碌,度过了新工作的三个月.博客许久未新,似乎对忙碌没有一点点防备.总结下来三个月不断的磨砺自己,努力从独乐乐转变到众乐乐,体会到不一样的是,连办公室的新玩意都能引起莫名的兴趣了 ...

  2. Redis主从复制原理总结

    和Mysql主从复制的原因一样,Redis虽然读取写入的速度都特别快,但是也会产生读压力特别大的情况.为了分担读压力,Redis支持主从复制,Redis的主从结构可以采用一主多从或者级联结构,Redi ...

  3. Beta版发布说明

    我们的作品“校友聊”软件的最终版本于6月19日最终发布了,下面我们将对自己的产品进行介绍. 在使用之前,首先要进行用户注册,用户可以自行设置自己的账号,姓名,密码,签名,头像等信息,头像信息也可以在文 ...

  4. Linux Network Commands

    https://www.tecmint.com/linux-network-configuration-and-troubleshooting-commands/ http://www.tldp.or ...

  5. Docker安装指定版本

    今天新增一个Docker服务器,Docker安装顺利,启动hello-world测试的时候却出现了问题: $ docker run hello-worldUnable to find image 'h ...

  6. [转帖]关于网络编程中MTU、TCP、UDP优化配置的一些总结

    关于网络编程中MTU.TCP.UDP优化配置的一些总结 https://www.cnblogs.com/maowang1991/archive/2013/04/15/3022955.html 感谢原作 ...

  7. scipy线性模块liner(linalg)

    #liner import numpy as np from scipy import linalg as lg arr=np.array([[1,1],[0,1]]) matr=np.mat('[1 ...

  8. Kivy crash 中文教程 实例入门 1. 第1个应用 Kivy App (Making a simple App)

    1.  空白窗口 在 PyCharm 中创建一个名为 TutorialApp 的项目,然后在该项目中新建了个名为 tutorial_app.py 的 Python 源文件,在 PyCharm 的代码编 ...

  9. 如何隐藏Win7登录界面的administrator用户名恢复

    很多朋友一直在用着第三方的Windows7系统盘来装机,例如下载了Ghost格式的一些装机盘.在这些第三方系统中,很多家都是默认使用administrator 帐户自动登陆的. 从安全的角度来讲,这样 ...

  10. JDK8字符串拼接的正确姿势

    1. 对列表中的元素进行拼接 以前,对一个列表中的字符串进行拼接时,常见的代码如示例1所示: 代码示例1 List<String> ids = ImmutableList.of(" ...