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 (≤), 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 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即可)的更多相关文章

  1. PAT 甲级 1079 Total Sales of Supply Chain

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

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

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

  3. 【PAT甲级】1079 Total Sales of Supply Chain (25 分)

    题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...

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

  5. 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点

    和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...

  6. PAT甲级——A1079 Total Sales of Supply Chain

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

  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. PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)

    树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

随机推荐

  1. CentOS Linux更改MySQL数据库目录位置

    引言: 由于MySQL的数据库太大,默认安装的/var盘已经再也无法容纳新增加的数据,没有办法,只能想办法转移数据的目录. 下面我整理一下把MySQL从/var/lib/mysql目录下面转移到/ho ...

  2. K8s基本概念入门

    序言 没等到风来,绵绵小雨,所以写个随笔,聊聊k8s的基本概念. k8s是一个编排容器的工具,其实也是管理应用的全生命周期的一个工具,从创建应用,应用的部署,应用提供服务,扩容缩容应用,应用更新,都非 ...

  3. Centos7服务器搭建部署显卡计算环境以及常用软件的安装使用

    安装好anaconda的服务器上会more你已经安装好jupyter notebook,执行下面的命令可以提供链接地址允许远程浏览器打开并访问: jupyter notebook --no-brows ...

  4. 《基于WEB的独立学院补考重修管理系统研究》论文笔记(二十)

    <基于WEB的独立学院补考重修管理系统研究>论文笔记(1) 一.基本信息 标题:基于WEB的独立学院补考重修管理系统研究 时间:2016 来源:南通大学杏林学院 关键词:WEB:补考重修管 ...

  5. C define详解

    1.简单的define定义 #define MAXTIME 1000 一个简单的MAXTIME就定义好了,它代表1000,如果在程序里面写 if(i<MAXTIME){.........} 编译 ...

  6. 10、Hadoop组件启动方式和SSH无密码登陆

    启动方式 一.各个组件逐一启动 hdfs: hadoop-daemon.sh start|stop namenode|datanode|secondnode yarn: yarn-demon.sh s ...

  7. Support Vector Machines

    支持向量机SVM. 简介 SVM核函数包括线性核函数.多项式核函数.径向基核函数.高斯核函数.幂指数核函数.拉普拉斯核函数.ANOVA核函数.二次有理核函数.多元二次核函数.逆多元二次核函数以及Sig ...

  8. 如何用okr做好目标规划

    有朋友和我吐槽公司总是规划一个个振奋人心的目标,让大家对工作充满了热情.然而好的开头却缺少追踪反馈没有好的结尾,那些大家所渴望达成的目标随着时间的流逝便逐渐没有了音信,不再有人主动提起,团队成员迎来的 ...

  9. Java web开发——文件的上传和下载

    一. 功能性需求与非功能性需求 要求操作便利,一次选择多个文件和文件夹进行上传:支持PC端全平台操作系统,Windows,Linux,Mac 支持文件和文件夹的批量下载,断点续传.刷新页面后继续传输. ...

  10. WinDbg常用命令系列---!handle

    !handle 简介 !handle扩展显示有关目标系统中一个或所有进程拥有的一个或多个句柄的信息. 使用形式 用户模式!handle [Handle [UMFlags [TypeName]]] !h ...