Source:

PAT A1106 Lowest Price in Supply Chain (25 分)

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:

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. 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的更多相关文章

  1. PAT1106:Lowest Price in Supply Chain

    1106. Lowest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CH ...

  2. [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)

    1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...

  3. PAT甲级——1106 Lowest Price in Supply Chain(BFS)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90444872 1106 Lowest Price in Supp ...

  4. 1106. Lowest Price in Supply Chain (25)

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

  5. A1106. Lowest Price in Supply Chain

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

  6. PAT A1106 Lowest Price in Supply Chain (25 分)——树的bfs遍历

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

  7. PAT 甲级 1106 Lowest Price in Supply Chain

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

  8. PAT 1106 Lowest Price in Supply Chain

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

  9. PAT甲级——A1106 Lowest Price in Supply Chain

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

随机推荐

  1. MyEclipse6.0中使用aptana插件,添加jquery提示功能

    MyEclipse6.0中使用aptana插件,添加jquery提示功能 第一:查看当前MyEclipse集成的eclipse的版本,, 查看路径    D:/MyEclipse 6.0/eclips ...

  2. Linux环境下安装PHP的mbstring模块

    cd /home/local/php-5.6.25/ext/mbstring/usr/local/php/bin/phpize./configure --with-php-config=/usr/lo ...

  3. BZOJ 3252: 攻略(思路题)

    传送门 解题思路 比较好想的一道思路题,结果有个地方没开\(long\) \(long\) \(wa\)了三次..其实就是模仿一下树链剖分,重新定义重儿子,一个点的重儿子为所有儿子中到叶节点权值最大的 ...

  4. linux find相关 (持续更新中)

    按名字查找 find . -name *.txt find . -name test* # . 指的是当前路径, 查找全局的话把. 换成/ 查找并删除多个文件 find -type f -name & ...

  5. anaconda里的python版本回退, requirements

    事情起因:我用的python3.7 , 同事机器学习的部分使用tensorflow,只支持python3.6, 所以我从3.7回退到3.6 conda create -n python36 pytho ...

  6. ASP.NET Core学习——5

    日志(Logging)ASP.NET Core内建支持日志,也允许开发人员轻松切换为他们想用的其他日志框架. 通过dependency-injection请求ILoggerFactory或ILogge ...

  7. vue中配置可修改的服务器接口api

    https://www.jianshu.com/p/377bfd2d9034?utm_campaign 太坑了,找了全网,几乎都不能用,也不知道哪写错了,这个是可以用的.

  8. pair的用法

    如何定义?(初始化) 1. pair<int,int>p; 2.定义即初始化,也可以这个样子 pair<,); 里面的类型还可以是string,double等. 3.还可以这样子初始 ...

  9. squid+stunnel搭建代理服务器

    设备:需要两台服务器 一,外部服务器  属于外网  ip 为 47.106.8.100 1,安装squid软件 2,vi  /etc/squid/squid.conf acl localnet src ...

  10. opencv bwlabel

    int bwLabel(const Mat& imgBw, Mat& imgLabeled) { Mat imgClone = Mat(imgBw.rows + , imgBw.col ...