PAT 1079 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
题目大意:给出树结构,找出零售商的总和。给出了供应商的原价,每经过一个经销商或者零售商价格上涨r%.求最终利润。
//我对题目的理解不好,这个r是个百分数,所以要/100,才可以的,并且当k=0时,后边存储的数是每个零售商的销量。
#include <iostream>
#include <vector>
#include <map>
#include<stdio.h>
#include<cmath>
using namespace std;
vector<int> vt[];
map<int,int> mp;
double sum=;
double p,r;
void dfs(int nd,int level){
if(vt[nd].size()==){
double temp=;
temp=pow(+r,level)*mp[nd];
sum+=temp;
return ;
}
for(int i=;i<vt[nd].size();i++){
dfs(vt[nd][i],level+);
}
} int main() {
int n;
scanf("%d %lf %lf",&n,&p,&r);
r=r/;
int tempk,temp;
for(int i=;i<n;i++){
scanf("%d",&tempk);
for(int j=;j<tempk;j++){
scanf("%d",&temp);
vt[i].push_back(temp);
}
if(tempk==){
scanf("%d",&temp);
mp[i]=temp;
}
}
dfs(,);
printf("%.1f",sum*p);
return ;
}
//第一次提交发生了段错误,检查发现是数据设置的太小了,应该是10^5才行,
1.使用邻接表来存储树,使用dfs进行遍历;
2.需要记住dfs的代码结构,首先是递归出口,出口处需要进行相应的计算;再是进行循环递归。
PAT 1079 Total Sales of Supply Chain[比较]的更多相关文章
- PAT 1079. Total Sales of Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 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 ...
- 1079 Total Sales of Supply Chain ——PAT甲级真题
1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...
- PAT 甲级 1079 Total Sales of Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560 A supply chain is a ne ...
- PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- 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 ...
- 1079 Total Sales of Supply Chain (25 分)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
随机推荐
- [jquery] jQuery 选择器>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- laravel 控制器多个方法共用一个路由
直接上代码: Route::get('Index/{action}', function(App\Http\Controllers\IndexController $index, $action){ ...
- 【RF库测试】DateTime库
术语说明: 1.Epoch指的是一个特定的时间:1970-01-01 00:00:00 UTC. 2.国际标准化组织的国际标准ISO 8601是日期和时间的表示方法,格式是 'YYYY-MM-DD h ...
- MySQL性能优化(四)-- MySQL explain详解
前言 MySQL中的explain命令显示了mysql如何使用索引来处理select语句以及连接表.explain显示的信息可以帮助选择更好的索引和写出更优化的查询语句. 一.格式 explain + ...
- C++11新特性之0——移动语义、移动构造函数和右值引用
C++引用现在分为左值引用(能取得其地址)和 右值引用(不能取得其地址).其实很好理解,左值引用中的左值一般指的是出现在等号左边的值(带名称的变量,带*号的指针等一类的数据),程序能对这样的左值进行引 ...
- iPhone较为基础的代码片段
Iphone代码片段导航 1.给UITableViewController添加ToolBar. self.navigationController.toolbarHidden = NO; //默认是隐 ...
- C++11-新增正则表达式
#include <regex> #include <iostream> #include <string> #include <atlstr.h> s ...
- ATL字符宏使用以及代码测试
// ATL_Convert.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #incl ...
- 【转】Go Channels
转自: http://kdf5000.com/2017/07/16/Go-Channels/ Golang使用Groutine和channels实现了CSP(Communicating Sequent ...
- 【Android N 7】使用量统计usagestats
Android N 7.1.1 高通 1. /data/system/usagestats/0 2. 每天使用量统计 /data/system/usagestats/0/daily 查看数值: cat ...