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 ...
随机推荐
- div + css 边框 虚线
div + css 边框 虚线 dotted:[点线|有点的|点线式边框|点虚线] .introduce { border:1px dotted gray; margin:8px 5px 8px 10 ...
- Karaf基础知识
Karaf 遵循OSGi开发规范的一个Apache框架 1.命令形如:scope:name 举例:feature:list 2 shell:completion tab键补齐 GLOBAL 补齐显 ...
- POJ3630-Phone List-Trie字典树模板题
Given a list of phone numbers, determine if it is consistent in the sense that no number is the pref ...
- 设置单网卡双ip
环境如下: [root@localhost ~]# cat /etc/redhat-releaseCentOS Linux release 7.7.1908 (Core) 安装时选择的最小化安装 -- ...
- Spring Boot跨域问题解决方案
@Configurationpublic class CorsConfig { @Bean public FilterRegistrationBean corsFilter() { UrlBasedC ...
- js 实用封装 点击按钮复制到剪贴板
封装剪贴板: function Copy(str) { var save = function (e) { //设置需要复制模板的内容 e.clipboardData.setData('text/pl ...
- SDL系列之 - 用SDL动态地画一个圆喽 && 设置背景色
#include <SDL.h> #include <stdlib.h> #include <string.h> #include <math.h> # ...
- 用redis实现悲观锁(后端语言以php为例)
1479 锁机制 通常使用的锁分为乐观锁,悲观锁这两种,简单介绍下这两种锁,作为本文的背景知识,对这类知识已经有足够了解的同学可以跳过这部分. 乐观锁 先来看下百度百科上的解释:大多是基于数据版本( ...
- python中 try、except、finally执行顺序
我们虽然经常用到try...except 作为异常补货,但是其实很少去研究try源码和机制,也许点进去看过,也是看不出个所以然来 class Exception(BaseException): &qu ...
- python--面向对象:继承
继承是创建新类的方式,新建的类可以继承多个父类(python里),父类又称为基类和超类,新建的类又称为派生类和子类 如果没有基类,python默认继承object祖类,object是所有类的基类 一. ...