PAT甲级——A1106 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 (≤), 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
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
int n, m;
double p, r;
int main()
{
cin >> n >> p >> r;
vector<vector<int>>people;
for (int i = ; i < n; ++i)
{
cin >> m;
vector <int>temp(m);
for (int i = ; i < m; ++i)
cin >> temp[i];
people.push_back(temp);
}
queue<int>node;
node.push();
int num = , level = -;
while (!node.empty())
{
queue<int>q;
while (!node.empty())
{
int root = node.front();
node.pop();
for (int i = ; i < people[root].size(); ++i)
q.push(people[root][i]);
if (people[root].size() == )//零售商
num++;
}
level++;
if (num > )
break;
node = q;
}
printf("%0.4f %d\n", p*pow((+r / ), level), num);
return ;
}
PAT甲级——A1106 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 ...
- PAT 甲级 1106 Lowest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464 A supply chain is a ne ...
- PAT A1106 Lowest Price in Supply Chain (25 分)——树的bfs遍历
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 Advanced 1106 Lowest Price in Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- PAT 甲级 1090 Highest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...
- PAT甲级——A1090 Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT_A1106#Lowest Price in Supply Chain
Source: PAT A1106 Lowest Price in Supply Chain (25 分) Description: A supply chain is a network of re ...
- PAT1106:Lowest Price in Supply Chain
1106. Lowest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CH ...
随机推荐
- 随笔-ansible-2
通过Ansible来搭建一套Web服务架构.[以AD-HOC的形式] Inventory文件内容如下: [proxy] 192.168.40.254 [app] 192.168.40.243 [nos ...
- go 简介与包
简介 Go语言是一种新的语言,一种并发的.带垃圾回收的.快速编译的语言.它具有以下特点: 1.它可以在一台计算机上用几秒钟的时间编译一个大型的Go程序. 2.Go语言为软件构造提供了一种模型,它使依赖 ...
- PHP算法之整数反转
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123输出: 321 示例 2: 输入: -123输出: -321示例 3: 输入: 120输出: 21注 ...
- 下载和安装mongodb4.2.0+robmongo可视化工具
一.mongodb下载安装 1.mongodb下载地址:https://www.mongodb.com/download-center/community?jmp=nav 下了很久很久,可以找其他途径 ...
- 【JZOJ6274】梦境
description analysis 其实可以贪心 先把区间按左端点排序,转折点也排序 扫一次转折点,把所有左端点在当前点左边的区间丢进优先队列里 按照贪心策略,对于某个转折点,一定选择右端点离它 ...
- thinkphp 规则路由
规则路由是一种比较容易理解的路由定义方式,采用ThinkPHP设计的规则表达式来定义. 规则表达式 规则表达式通常包含静态地址和动态地址,或者两种地址的结合,例如下面都属于有效的规则表达式: 'my' ...
- 可拖拽排序的vue组件
最近在优化一个vue的博客系统,想实现文章列表处的文章拖拽功能.就试了一下awe-dnd vue插件,觉得还挺好用的. 安装 npm install awe-dnd --save 使用 在main.j ...
- sessionStorage 和 localStorage的区别
sessionStorage.setItem('userName',userName) // 存 sessionStorage.getItem('userName') // 取 sessionStor ...
- CCPC 2019 网络赛 1006 Shuffle Card
// 签到题,比赛时候写双向链表debug了半天,发现有更好方法,记录一下. Shuffle Card HDU 6707 题意: 有一 \(n\) 张卡片,编号 \(1~n\) ,给定初始编号 ...
- iOS开发系列-NSURLSession
概述 NSURLSession是从iOS7开始出现的.NSURLSession比NSURLConnection简单很多并且避免了很多坑,因此目前公司项目大部分由NSURLConnection过度为NS ...