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 ...
随机推荐
- Replication Controller 和 Replica Set
使用Replication Controller . Replica Set管理Pod Replication Controller (RC) 简写为RC,可以使用rc作为kubectl工具的快速管理 ...
- BS开发扫盲篇-前端技术风云录
BS开发扫盲篇-前端技术风云录 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HTML诞生 HTML(HyperText Markup Language)超文本标记语言 ...
- springboot在idea的RunDashboard如何显示出来
找到.idea文件下的workspace.xml,并找到RunDashboard 加入如下配置 <option name="configurationTypes"> & ...
- Spring源码窥探之:单实例Bean的创建过程
finishBeanFactoryInitialization(beanFactory);初始化剩下的所有的单实例(非懒加载)Bean(Instantiate all remaining (non-l ...
- ctx控制超时的使用
cancel package main import ( "context" "fmt" "time" ) func gen(ctx con ...
- c博客作业01——顺序 分支结构
本章学习总结 1.1 学习内容总结 ·学习switch分支的使用,switch后加括号(),括号内填一个变量或字符 如 switch (a) { case 2: case 3: default: } ...
- es6中class类的静态方法、实例方法、实例属性、(静态属性)
关于类有两个概念,1,类自身,:2,类的实例对象 总的来说:静态的是指向类自身,而不是指向实例对象,主要是归属不同,这是静态属性的核心. 难点1:静态方法的理解 class Foo { static ...
- windows sh.exe 中文乱码
idea 需要重启 export LANG=zh_CN.utf-8 alias ls='ls --show-control-chars --color=auto'
- Java后台读取excel表格返回至Web前端
如果是做连接数据库的话,系统难度就降低了不少:这次本人也算是体会到数据库的方便了吧(不过以后云储存好像会更受欢迎些):比如说查询列出所有数据吧:数据库每个表每一列都有列名,正常的做法是遍历数据库表,d ...
- 配置nRF52832 的NFC 专用引脚为 GPIO
nRF52832 是支持NFC的,真可惜本码农没用过. NFC的引脚为 P0.09/P0.10,这两个引脚正常情况下是不能直接当做GPIO来用的,要用的时候,需要在编译环境配置一个宏. 下面是Keil ...