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. spring boot 在不同环境下读取不同配置文件的一种方式

    在工程中,通常有根据不同的环境读取不同配置文件的需求,对于spring boot 来说,默认读取的是application.yml 或者 application.properties.为了区分不同的环 ...

  2. Wechat login authorization(OAuth2.0)

    一.前言 昨天小组开了个会,让我今天实现一个微信网页授权的功能,可以让用户在授权之后无需再次登录既可进入用户授权界面.在这之前我也从没接触过微信公众号开发之类的,也不知道公众号后台是啥样子的,自己所在 ...

  3. centos6.5虚拟机安装后,没有iptables配置文件

    openstack环境里安装centos6.5系统的虚拟机,安装好后,发现没有/etc/syscofig/iptables防火墙配置文件. 解决办法如下: [root@kvm-server005 ~] ...

  4. Java开发23种设计模式之禅

    六大原则 23种设计模式: 总体来说设计模式分为三大类: *创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. *结构型模式,共七种:适配器模式.装饰器模式.代理模式.外 ...

  5. 如何启动Intel VT-X及合理利用搜索

    昨天安装Vmware的时候不幸遇到了Vt-X被禁用的麻烦,上网百度了一下才知道要进入Bois进行设置.说起百度就不得不提到模糊搜索这个概念.这个特性的优点和缺点可谓同等突出,有了模糊搜索大家可以在信息 ...

  6. 《Linux内核设计与实现》第十八章学习笔记

    第十八章 调试 [学习时间:1小时 总结博客时间:1小时15分] [学习内容:出现bug的原因.内核调试器gdb.使用Git进行二分查找] 内核级开发的调试工作远比用户级开发艰难,它带来的风险比用户级 ...

  7. jsp中获取不到servlet的cookie

    今天做登陆,发现jsp中使用document.cookie获取不到servlet生成的cookie,我们可以在浏览器的cookie文件夹中发现,servlet中生成的cookie和jsp中的生成的路径 ...

  8. jquery打印页面(jquery.jqprint)

    使用jquery进行打印时,所需js包:jquery-1.4.4.min.js.jquery.jqprint-0.3.js 但如果使用高版本的jquery(jquery-1.9.1.min.js)时, ...

  9. 实战框架ABP

    abp及实战框架概述 接触abp也快一年了,有过大半年的abp项目开发经验,目前项目中所用的abp框架版本为0.10.3,最新的abp框架已经到了1.4,并且支持了asp.net core.关于abp ...

  10. PAT 1013 数素数

    https://pintia.cn/problem-sets/994805260223102976/problems/994805309963354112 令P~i~表示第i个素数.现任给两个正整数M ...