PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)
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 (≤), 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
题意:
在一个供应链中,有批发商,中间商,零售商,只有零售商会对普通顾客出售商品,商品的原价是固定,每经过一级经销商,商品的价格会增加t%,题目会给出美国零售商的货物数量,要求你求出所有在售商品的价值总和,在输入中先给出结点数量n,然后在接下来的n行中,依次在每一行给出0~n-1号结点的子节点数量,子节点编号,如果子节点数量为0,那么说明该结点是叶节点,本行第二个数是零售商的货物数量
————————————————
版权声明:本文为CSDN博主「热心市民小黎」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_33657357/article/details/8234534
题解:
先用结构体,结构体里out向量存储下面到哪些点
bfs,根据入度为0,找到根节点,借用队列,一层层向外计算,当前节点的 val = 上一个的val * (1+r/100)
AC代码:
#include<bits/stdc++.h>
using namespace std;
int in[];
struct node{
double val;
vector<int>out;
}a[];
queue<int>q;
int xiao[];
int n;
double p,r;
double s=;
int main(){
cin>>n>>p>>r;
memset(in,,sizeof(in));
for(int i=;i<n;i++){
int k;
cin>>k;
if(k==) cin>>xiao[i];
for(int j=;j<=k;j++){
int x;
cin>>x;
a[i].out.push_back(x);
in[x]++;
}
}
int root=-;
for(int i=;i<n;i++){
if(in[i]==){
root=i;
break;
}
}
a[root].val=p;
q.push(root);
while(!q.empty()){
int x=q.front();
q.pop();
if(a[x].out.size()==){
s+=xiao[x]*a[x].val;
}else{
double u=a[x].val*(+r/);
for(int i=;i<a[x].out.size();i++){
int y=a[x].out.at(i);
a[y].val=u;
q.push(y);
}
}
}
printf("%.1f",s);
return ;
}
PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)的更多相关文章
- 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 ...
- 【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 ...
- PAT甲级——A1079 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)
时间限制 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 Level) 1079. Total Sales of Supply Chain (25)
树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
随机推荐
- Python并发编程-concurrent包
Python并发编程-concurrent包 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.concurrent.futures包概述 3.2版本引入的模块. 异步并行任务编程 ...
- ansible中的常用循环模块with_items
ansible中的循环模块有很多,不过with_items最为常用,且较为简单,循环模块最多的功能就是将重复性的任务简单化,如下例子所示: - hosts: all remote_user: root ...
- ACAG 0x02-8 非递归实现组合型枚举
ACAG 0x02-8 非递归实现组合型枚举 之所以专门来写这道题的博客,是因为感觉从最根本处了解到了递归的机器实现. 主要的就是两个指令--Call和Ret. Call指令会将返回地址入栈(系统栈) ...
- Python开发应用之-SQL 建索引的几大原则
SQL 建索引的几大原则: 最左前缀匹配原则,非常重要的原则,mysql会一直向右匹配直到遇到范围查询(>.<.between.like)就停止匹配,比如a = 1 and b = ...
- SparkSQL读写外部数据源-通过jdbc读写mysql数据库
object JdbcDatasourceTest { def main(args: Array[String]): Unit = { val spark = SparkSession .builde ...
- 利用GitHub+Node.js+Hexo搭建个人博客
本篇是自己在搭建Hexo博客平台时的一个过程记录.(2019.9.13实测有效) GitHub 账号注册 因为此文所搭建的个人博客是基于GitHub平台服务的,所以首先是注册GitHub,当然已有账号 ...
- Boosting and AdaBoost
Boosting是一种从一些弱分类器中创建一个强分类器的集成技术(提升算法). 它先由训练数据构建一个模型,然后创建第二个模型来尝试纠正第一个模型的错误.不断添加模型,直到训练集完美预测或已经添加到数 ...
- asp.net web开发——文件的上传和下载
HTML部分 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.a ...
- ssh集成
导入pom依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...
- socket简单实践
目录 socket模块: family(socket家族) fileno=None 请忽略,特殊用途 socket模块: 把tcp/ip协议层的各种数据封装啦.数据发送.接收等通过代码已经给你封装 应 ...