PAT_A1106#Lowest Price in Supply Chain
Source:
Description:
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 Pand 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 lowest price a customer can expect from some 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 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. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in one line the lowest price we can expect from some retailers, accurate up to 4 decimal places, and the number of retailers that sell at the lowest price. There must be one space between the two numbers. It is guaranteed that the all the prices will not exceed 1.
Sample Input:
10 1.80 1.00
3 2 3 5
1 9
1 4
1 7
0
2 6 1
1 8
0
0
0
Sample Output:
1.8362 2
Keys:
Attention:
- 加上剪枝的话,层次遍历会更快一些,深度遍历比较好写-,-
Code:
/*
time: 2019-06-28 14:08:25
problem: PAT_A1106#Lowest Price in Supply Chain
AC: 24:26 题目大意:
供应链网络:供应商->经销商->零售商->消费者
只有一个供应商,经销商以价格P从供应商进货,再以溢价r%出售给下一级经销商,最终至零售商出售给消费者
求出消费者购买商品的最低价格
输入:
第一行给出,结点数N<=1e5(编号0~n-1,root为0),出厂价P,溢价百分率r
接下来N行,结点i的孩子结点数量,各孩子结点编号
输出:
最低价格(4位小数),零售商数量(叶子结点数量) 基本思路:
实质就是遍历一个树,求叶子结点中最浅的层次和个数
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int M=1e5+;
vector<int> chain[M];
int cnt=,minDeep=M;
double r,p; void Travel(int root, int hight)
{
if(minDeep < hight)
return;
if(chain[root].size() == )
{
if(hight < minDeep)
{
minDeep = hight;
cnt = ;
}
else if(minDeep == hight)
cnt++;
return;
}
for(int i=; i<chain[root].size(); i++)
Travel(chain[root][i], hight+);
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,k,v;
scanf("%d%lf%lf", &n,&p,&r);
for(int i=; i<n; i++)
{
scanf("%d", &k);
for(int j=; j<k; j++)
{
scanf("%d", &v);
chain[i].push_back(v);
}
}
Travel(,);
printf("%.4f %d", p*pow((1.0+r/),minDeep), cnt); return ;
}
PAT_A1106#Lowest Price in Supply Chain的更多相关文章
- PAT1106:Lowest Price in Supply Chain
1106. Lowest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CH ...
- [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)
1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...
- PAT甲级——1106 Lowest Price in Supply Chain(BFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90444872 1106 Lowest Price in Supp ...
- 1106. Lowest Price in Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- A1106. Lowest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT A1106 Lowest Price in Supply Chain (25 分)——树的bfs遍历
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT 甲级 1106 Lowest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464 A supply chain is a ne ...
- PAT 1106 Lowest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT甲级——A1106 Lowest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
随机推荐
- Android中实现对/system/bin/surfaceflinger进程进行拦截和注入
对于Android for arm上的so注入(inject)和挂钩(hook),网上已有牛人给出了代码inject.由于实现中的ptrace函数是依赖于平台的,所以不经改动只能用于arm平台.本文将 ...
- c go数据类型对应关系
DataType C cgo sizeof--------------------+--------------------+------------------------------------- ...
- Java-Class-FC:java.util.Optional
ylbtech-Java-Class-FC:java.util.Optional 1.返回顶部 2.返回顶部 1.1. import java.util.Optional; 1.2.1. @Api ...
- 【linux】netlink
Netlink实现网卡上下线监控 https://blog.csdn.net/sourthstar/article/details/7975999
- idea中如何查看jar包中的源码(非maven),以oracle的ojdbc为例
文章目录 背景 解决 背景 工作需要查看oracle的部分源码(ojdbc.jar),maven并没有这个依赖,单纯的导入jar包无法查看. 解决 将ojdbc.jar 安装到本地仓库,maven从本 ...
- PAT_A1117#Eddington Number
Source: PAT A1117 Eddington Number (25 分) Description: British astronomer Eddington liked to ride a ...
- 1067 Sort with Swap(0, i) (25 分)
Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing order ...
- Django框架(一)—— 安装使用Django
目录 Django入门 一.web应用 二.C/S 和B/S 架构 三.python中的web框架 四.http协议 五.URL简介 六.Django的安装和使用 Django入门 一.web应用 W ...
- java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
问题:Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationCont ...
- apach hadoop2.6 集群利用Phoenix 4.6-hbase 批量导入并自动创建索引
基础环境: 1.安装apach 版本hadoop2.6 2.部署hbase1.0.0 3.下载phoenix-4.6.0-HBase-1.0.下载地址(http://mirror.nus.edu.sg ...