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 ...
随机推荐
- iscroll refresh无效解决办法
最近用iscroll.js 写移动页面,效果还是挺好的.但,还是会遇到重新初始化的问题. var myScroll = new IScroll('#rule_wrapper',{ click:true ...
- mockjs 使用以及反向校验
一.背景 前端开发需要依赖后端接口 后端接口输出慢.接口规范随时可能会变,而前端毫无感知 前端需要自己 mock 假数据 json 文件 假数据 json 数据内容是静态的,测试不同返回情况需要修改 ...
- BZOJ 1927: [Sdoi2010]星际竞速(费用流)
传送门 解题思路 仿照最小路径覆盖问题,用费用流解决此题.最小路径覆盖问题是拆点连边后用\(n-\)最大匹配,这里的话也是将每个点拆点,源点向入点连流量为\(1\),费用为\(0\)的边,向出点连流量 ...
- Mac 安装react-native 环境踩坑记
我的工程创建时间是2019.7.11号下午 :首先看一下最后我的工程的package.json各个包的版本: { "name": "MyApp", &quo ...
- 『Golang』—— 标准库之 os
Golang 的 os 库基本承袭 Unix 下 C 语言的用法 path 库: func Base(path string) string //取文件名,不含目录部分 func Dir(path s ...
- FreeBSD_11-系统管理——{Part_a-bhyve}
;; 创建 vm: #!/usr/bin/env zsh bridgeIF=bridge0 laggIF=lagg0 tapIF=tap0 phyIF_0=re0 phyIF_1=em0 isoPat ...
- Lucene字段
字段是最低单元或索引过程的起点.它代表其中一个键被用于识别要被索引的值的键值对关系.用于表示一个文件的内容的字段中将具有键为“内容”和值,可以包含文本或文档的数字内容的部分或全部. Lucene可以索 ...
- 区分slice,splice,split
原文:https://www.cnblogs.com/webjoker/p/5218114.html 1.slice(数组) 用法:array.slice(start,end) 解释:该方法是对数组进 ...
- SDL系列之 - 用SDL动态地画一个圆喽 && 设置背景色
#include <SDL.h> #include <stdlib.h> #include <string.h> #include <math.h> # ...
- vue中ref的使用(this.$refs获取为undefined)
如果你获取到的总是空的,你注意一下: 1.你在哪里调用,和你调用的对象 试试在mounted()里面调用有效果没有 调用的对象是本来就存在的,还是需要数据渲染之后才会出现的,同理,在mounted() ...