PAT1079 :Total Sales of Supply Chain
1079. Total Sales of Supply Chain (25)
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 思路
简单的dfs问题,每次到达叶节点加上对应的总价就行
代码
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
vector<vector<int>> graph(100001);
vector<int> amount(100001);
double price,rate,total = 0; void dfs(int root,double curprice,int level)
{
if(level != 0)
curprice *= (1.0 + rate);
if(amount[root] > 0)
{
total += curprice * amount[root];
}
else
{
for(int i = 0;i < graph[root].size();i++)
dfs(graph[root][i],curprice,level + 1);
}
} int main()
{
int N;
while(cin >> N >> price >> rate)
{
rate /= 100.0;
for(int i = 0;i < N;i++)
{
int k;
cin >> k;
if(k == 0)
cin >> amount[i];
else
{
for(int j = 0;j < k;j++)
{
int tmp;
cin >> tmp;
graph[i].push_back(tmp);
}
}
}
dfs(0,price,0);
cout << fixed << setprecision(1) << total << endl;
}
}
PAT1079 :Total Sales of Supply Chain的更多相关文章
- pat1079. Total Sales of Supply Chain (25)
1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- PAT-1079 Total Sales of Supply Chain (树的遍历)
1079. Total Sales of Supply A supply chain is a network of retailers(零售商), distributors(经销商), and su ...
- PAT 1079 Total Sales of Supply Chain[比较]
1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...
- 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 ...
- 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 ...
- 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 ...
- 1079 Total Sales of Supply Chain ——PAT甲级真题
1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...
- 1079. Total Sales of Supply Chain (25)
时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- 1079. Total Sales of Supply Chain (25) -记录层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
随机推荐
- 【Android 应用开发】Android - 时间 日期相关组件
源码下载地址 : -- CSDN : http://download.csdn.net/detail/han1202012/6856737 -- GitHub : https://github.co ...
- Cocos2D的随机数生成函数
有很多种方法生成随机数.但是只有arc4random函数生成的最接近于"真随机(truly random)"数.(而且不需要种子) 其变体函数arc4random_uniform生 ...
- /dev、/sys/dev 和/sys/devices 和udev的关系
/dev,设备文件存储目录,应用程序通过对这些文件的读写和控制,可以访问实际的设备: /sys/devices目录,按照设备挂接的总线类型,组织成层次结构,保存了系统所有的设备:是文件系统管理设备的最 ...
- Effective C++总结
条款01:视C++为一个语言联邦(View C++ as a federation of languages.) C++主要的四个次语言: (1)C.说到底C++仍是以C为基础:(2)Object-O ...
- Linux文件与目录管理 - ls, cp, mv
[root@www ~]# ls [-aAdfFhilnrRSt] 目录名称 [root@www ~]# ls [--color={never,auto,always}] 目录名称 [root@www ...
- 速度之王 — LZ4压缩算法(二)
LZ4 (Extremely Fast Compression algorithm) 项目:http://code.google.com/p/lz4/ 作者:Yann Collet 本文作者:zhan ...
- win7 64位系统,vs2010下配置OpenGL开发环境
glut下载地址: http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip 或者:http://user.xmission. ...
- 那些年Android开发中遇到的坑
使用静态变量来缓存数据时,不管是在Application类还是其他类,都要注意因应用重建而引发的问题. 使用DecorView作为PopupWindow的anchorView时,在华为P7中它是显示在 ...
- android EventBus详解(一)
EventBus 是一款针对Android优化的发布/订阅事件总线.主要功能是替代Intent, Handler, BroadCast 在 Fragment,Activity,Service,线程之间 ...
- Hadoop DataNode不能正常工作的原因
在把Hadoop环境搭建成功,并且也Hadoop的各个组件都正常工作.在重启过几次Hadoop后发现DataNode不能正常工作,打开Hadoop 的后台http://localhost:50030和 ...