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 Pand 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 (≤), 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 1.
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 <bits/stdc++.h>
using namespace std;
vector<int> v[];
int a[];
int n,k,x;
double price,per,y;
double ans = ;
void find(int m,double p)
{
if(a[m])
{
ans = ans + p*a[m];
return ;
}
else
{
for(int i=; i < v[m].size(); i++)
{
find(v[m][i],p*per);
}
return ;
}
} int main()
{
memset(a,,sizeof(a));
scanf("%d %lf %lf",&n,&price,&per);
per = (+per)/;
for(int i=;i<n;i++)
{
scanf("%d",&k);
if(!k){
scanf("%lf",&y);
a[i] = y;
}
else{
for(int j=;j<k;j++)
{
scanf("%d",&x);
v[i].push_back(x);
}
}
}
find(,price);
printf("%.1lf\n",ans); return ;
}
1079 Total Sales of Supply Chain (25 分)的更多相关文章
- 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甲级】1079 Total Sales of Supply Chain (25 分)
题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...
- 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 ...
- 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点
和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...
- 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 ...
- PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)
树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- 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 Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...
随机推荐
- Hadoop文档 索引
Hadoop中文文档 http://hadoop.apache.org/docs/r1.0.4/cn/index.html Hadoop资料整理 http://www.itpub.net/thread ...
- windows常用快捷键(转载)
f1 显示当前程序或者windows的帮助内容. f2 当你选中一个文件的话,这意味着“重命名” f3 当你在桌面上的时候是打开“查找:所有文件” 对话框 f10或alt 激活当前程序的菜单栏 win ...
- 【BZOJ2795】[Poi2012]A Horrible Poem hash
[BZOJ2795][Poi2012]A Horrible Poem Description 给出一个由小写英文字母组成的字符串S,再给出q个询问,要求回答S某个子串的最短循环节.如果字符串B是字符串 ...
- Red Black Tree java.util.TreeSet
https://docs.oracle.com/javase/9/docs/api/java/util/SortedMap.html public interface SortedMap<K,V ...
- Cocos2d-JS 项目接入 触控广告平台(基于anysdk2.0.2)
本文以Cocos2d-JS项目作为示例,讲解如何集成AnySDK-JS. 一.如何创建项目我就省略了,直接进入主题. 1.1 首先,我需要下载anysdk框架包,下载地址:http://www.any ...
- java之快速排序
//基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据 ...
- Linux就该这么学--命令集合3(文本文件编辑命令)
1.cat命令查看纯文本文件(较短):(cat [选项] [文件]) cat -n showpath.sh 附录: -n 显示行号 -b 显示行号(不包括空行) -A 显示出“不可见”的符号,如空格, ...
- Sql Server 2016 创建内存数据库
官方教程:https://docs.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/survey-of-initial-area ...
- CALayer的隐式动画
CALayer的使用 在我的理解中CALayer就是iOS中利用图层精简非交互式绘图.那么那些核心动画类.也就是变化图层的非交互式绘制规则而已.其中的本质就是将CALayer中的内容转化为map图.从 ...
- Linux-VMware三种网络模式
虚拟机网络模式 对于VMware虚拟软件来说,有三种网络模式 1.桥接 2.NAT 3.Host-only 桥接 桥接网络是指本地物理网卡和虚拟网卡通过VMnet0虚拟交换机进行桥接,因此物理网卡和虚 ...