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 Studio下使用NDK的流程
我要重新拿回持之以恒徽章!! 老规矩,先说看能学会什么:ANDROID STUDIO下NDK的使用方法.JNI的基本使用方法,C语言调用JAVA的方法. 首先要下载NDK,如果你没有VPN可以来htt ...
- saiku 网站简介
Saiku web:http://docs.analytical-labs.com/saiku/documentation/2013/08/15/datasources.html Click &quo ...
- 运行Myeclipse时,如何删除IVM窗口
windows------>preference------>run/debug------->lauching--------->percpectives,改成never,n ...
- android 自定义gallerey并实现预览功能
自从Gallery被谷歌废弃以后,Google推荐使用ViewPager和HorizontalScrollView来实现Gallery的效果.的确HorizontalScrollView可以实现Gal ...
- redis持久化AOF与RDB
RDB 持久化可以在指定的时间间隔内生成数据集的时间点快照(point-in-time snapshot). AOF 持久化记录服务器执行的所有写操作命令,并在服务器启动时,通过重新执行这些命令来还原 ...
- nodejs--(一)http模板篇
Nodejs http模块可以创建服务器应用实例,也能发送http请求 1.http.get(options[, callback]) 发送简单Get请求,并响应 var http=require(' ...
- 南京邮电大学java程序设计作业在线编程第六次作业
王利国的的 "Java语言程序设计第6次作业(2018)" 详细 主页 我的作业列表 作业结果详细 总分:100 选择题得分:60 1. Java中所有类的父类是(). A.Fa ...
- JavaScript中对象数组,如何给对象添加一个新属性
var a =[{name: 'Tom',age:20},{name: 'Tom2',age:22}] 现在给a数组中的第一个对象添加性别属性 a[0]['gender']='women' a[0][ ...
- Day9 进程理论 开启进程的两种方式 多进程实现并发套接字 join方法 Process对象的其他属性或者方法 守护进程 操作系统介绍
操作系统简介(转自林海峰老师博客介绍) #一 操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬件的竞争变得有序 #二 多道技术: 1.产生背景: ...
- 没人看系列-----html随笔
<!DOCTYPE> 目录 没人看系列-----html/css详解 前言 不多说这段时间写了好多好多前端的东西,以至于自己重新返回看了一遍前端的所有技术.故此做个总结,准备学东西的请绕行 ...