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 (≤10​5​​), 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:

K​i​​ ID[1] ID[2] ... ID[K​i​​]

where in the i-th line, K​i​​ 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. K​j​​ being 0 means that the j-th member is a retailer, then instead the total amount of the product will be given after K​j​​. 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 10​10​​.

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[比较]的更多相关文章

  1. PAT 1079. Total Sales of Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  2. 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 ...

  3. 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 ...

  4. 1079 Total Sales of Supply Chain ——PAT甲级真题

    1079 Total Sales of Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), a ...

  5. PAT 甲级 1079 Total Sales of Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805388447170560 A supply chain is a ne ...

  6. PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...

  7. 1079. Total Sales of Supply Chain (25)

    时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  8. 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  9. 1079 Total Sales of Supply Chain (25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

随机推荐

  1. OpenCV学习:实现简单的图像叠加

    本实例使用简单的线性叠加方法来实现两幅图像的叠加,主要使用的知识如下: 1)线性融合 2)addWeighted函数 //! computes weighted sum of two arrays ( ...

  2. Python 爬虫知识点 - XPath

    http://cuiqingcai.com/2621.html 一.基础介绍 <bookstore> <book> <title>Harry Potter</ ...

  3. [转载]Linux I/O 调度方法

    http://scoke.blog.51cto.com/769125/490546 IO调度器的总体目标是希望让磁头能够总是往一个方向移动,移动到底了再往反方向走,这恰恰就是现实生活中的电梯模型,所以 ...

  4. PyQt4将窗口放在屏幕中间

    以下脚本显示了将窗口放在屏幕中间位置的方法. #!/usr/bin/python # -*- coding:utf-8 -*- import sys from PyQt4 import QtGui c ...

  5. 通过([AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)] )在前台html页面调用cs方法

    app_code中CS代码( Cs页面文件名public class ajaxGET): [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement ...

  6. LeetCode——Best Time to Buy and Sell Stock II

    Description: Say you have an array for which the ith element is the price of a given stock on day i. ...

  7. LeetCode——Single Number

    Description: Given an array of integers, every element appears twice except for one. Find that singl ...

  8. TCP协议的基本规则和在Java中的使用

    TCP协议是面向连接的,相对于UDP协议来说效率较低,但是比较安全,数据不容易丢失.TCP协议类似打电话的过程,在一端拨号时必须等待对方回应,确定两端建立了连接通道才能传送信息. 在Java中TCP被 ...

  9. window.postMessage跨文档通信

    window.postMessage 1.浏览器兼容情况:IE8+.chrome.firefox等较新浏览器都至此. 2.使用方法: a.otherWindow.postMessage( messag ...

  10. Hibernate(1)——数据访问层的架构模式<转>

    数据库的概念.逻辑.数据模型概念 应用程序的分层体系结构发展 MVC设计模式与四层结构的对应关系 持久层的设计目标 数据映射器架构模式 JDBC的缺点 Hibernate简介 迅速使用Hibernat ...