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. 用 webpack 构建 node 后端代码,使其支持 js 新特性并实现热重载

    https://zhuanlan.zhihu.com/p/20782320?utm_source=tuicool&utm_medium=referral

  2. HDU2717BFS

    /* WA了12发简直不能忍! . 题意非常简单.从正整数a变为b有三种方法: +1,-1.*2 特殊情况一:a与b相等不须要搜索 特殊情况二:a>b时.结果必定是a-b不需搜 特殊情况三:比較 ...

  3. ionic安装及测试

    官方教程: http://ionicframework.com/getting-started/ 官方教程写得比较简单,简单来说就是 1)安装nodejs(安装方法:http://www.cnblog ...

  4. 解决IE中img.onload失效的方法

    解决IE中img.onload失效的方法 - CoffeeCat's IT Blog - IT博客 http://www.cnitblog.com/CoffeeCat/archive/2008/02/ ...

  5. sqlmap tutorial

    svn checkout https://svn.sqlmap.org/sqlmap/trunk/sqlmap sqlmap-dev sqlmap.py -u "http://www.isl ...

  6. nested exception is org.springframework.beans.factory.BeanCreationException: 不能注入对象 创建对象失败 spring

    [出现错误的背景] 在使用Spring+SpringMVC+Mybatis SSM集成框架时,服务器启动就会报错. [错误根源] XML配置错误. [解决方案] 第一步.查找springmvc.xml ...

  7. jquery类似方法的比较(一)

    1. $(div + p) & $(div ~ p) & $(div p) & $(div > p) $(div + p)选择紧挨在div后面的P元素 $(div ~ p ...

  8. javascript字符串函数

    substring() 从字符串中提取一些字符 <script type="text/javascript"> var str="Hello world!&q ...

  9. 以吃货的角度去理解云计算中On-Premise、IaaS、PaaS和SaaS

    了解云计算的一定都听过四个“高大上”的概念:On-Premise(本地部署),IaaS(基础设施及服务).PaaS(平台即服务)和SaaS(软件即服务),这几个术语并不好理解.不过,如果你是个吃货,还 ...

  10. 【BZOJ4774/4006】修路/[JLOI2015]管道连接 斯坦纳树

    [BZOJ4774]修路 Description 村子间的小路年久失修,为了保障村子之间的往来,法珞决定带领大家修路.对于边带权的无向图 G = (V, E),请选择一些边,使得1 <= i & ...