PAT 1106 Lowest Price in Supply Chain
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 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 (≤10^5), 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 10^10.
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
#include<iostream> //类似于树的层级遍历
#include<vector>
#include<iomanip>
#include<math.h>
using namespace std;
int minlevel=9999999, num=0;
void level_traversal(vector<vector<int>> &chain, int level, int root){
if(chain[root].size()!=0){
for(int i=0; i<chain[root].size(); i++)
level_traversal(chain, level+1, chain[root][i]);
}else{
if(minlevel>level){
minlevel=level;
num=1;
}else if(minlevel==level)
num++;
}
}
int main(){
int N;
double p, r;
cin>>N>>p>>r;
vector<vector<int>> chain;
for(int i=0; i<N; i++){
int n;
cin>>n;
vector<int> temp(n,0);
for(int j=0; j<n; j++)
cin>>temp[j];
chain.push_back(temp);
}
level_traversal(chain, 0, 0);
cout<<setiosflags(ios::fixed)<<setprecision(4)<<p*pow(1+0.01*r, minlevel);
cout<<" "<<num<<endl;
return 0;
}
PAT 1106 Lowest Price in Supply Chain的更多相关文章
- 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)
1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...
- PAT 甲级 1106 Lowest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464 A supply chain is a ne ...
- PAT Advanced 1106 Lowest Price in Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- 1106. Lowest Price in Supply Chain (25)
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 (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
统计树的最小层数以及位于该层数上的叶子节点个数即可. 代码里建树我用了邻接链表的存储方式——链式前向星,不了解的可以参考,非常好用: http://www.cnblogs.com/chenxiwenr ...
- 【PAT甲级】1106 Lowest Price in Supply Chain (25分)
题意:输入一个正整数N(<=1e5),两个小数P和R,分别表示树的结点个数和商品原价以及每下探一层会涨幅的百分比.输出叶子结点深度最小的商品价格和深度最小的叶子结点个数. trick: 测试点1 ...
随机推荐
- git diff比较使用
git diff 等同于 git diff HEAD jiqing@ubuntu:/home/wwwroot/default/siemens/new_hotel$ git diff HEAD diff ...
- error: undefined reference to 'property_set (转载)
转自:http://blog.csdn.net/u011589606/article/details/23474241 in the cpp file, please include #include ...
- 【WIP】Bootstrap modal
创建: 2017/09/28 更新: 2017/10/14 标题加上[WIP]
- Balanced Lineup(线段树)
http://poj.org/problem?id=3264 题意:n个数,q个询问,输出[l,r]中最大值与最小值的差. #include <stdio.h> #include < ...
- codevs2503失恋28天......(背包dp)
503 失恋28天-缝补礼物 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 话说上回他给女孩送了n件礼物,由于是廉价的所以 ...
- 开源矿工README
点击加入 NTMiner官方QQ群: 863725136 开源矿工内置的所有内核均为原版,开源矿工永远不会额外增加矿工支出: 开源矿工永远开源: 开源矿工永远不会去破解国人开发的内核: 下载地址 阿里 ...
- 拼接sql ()
SELECT ID,FORMNAME,NODENAME,SEQUENCE, NAME, STATE, NOWTIMES, WORK.FQREALNAME||'('||FQDEPT.FULLN ...
- Expected one result (or null) to be returned by selectOne(), but found: 2 和 java.lang.UnsupportedOperationException异常
在学习MyBatis的时候,简简单单的MyBatis+MySql的增删改查操作,但是却出了问题. 刚开始数据库只有一条数据的时候,岁月静好,一切看起来都那么的OJBK.但是,当我往数据库插入第二条数据 ...
- ACM_3n+1问题(克拉兹问题+线段树区间查询最大值)
3n+1问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 考虑如下的序列生成算法:从整数n开始,如果n是偶数,把它除以2:如果 ...
- dynamic_cast 与 typeid
C++中的类型转换分为两种: 隐式类型转换: 显式类型转换. 隐式类型转换一般都是不经意间就发生了,比如int + float 时,int就被隐式的转换为float类型了. 显示类型转换包括四种方式: ...