PAT1106:Lowest Price in Supply Chain
1106. Lowest Price in Supply Chain (25)
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 (<=105), 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 1010.
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 思路
类似 pat1079 的问题,bfs找到最长的路径然后计算价格就行。
代码
#include<iostream>
#include<vector>
#include<queue>
#include<iomanip>
using namespace std;
vector<vector<int>> graph(100000);
vector<bool> visits(100000,false);
/*
1.输入,构图
2.bfs找最短
3.迭代求乘积
*/ int bfs(int& cnt)
{
queue<int> q;
int minnum = 233333,level = 1,label = -1;
q.push(0);q.push(label);
while(!q.empty())
{
int tmp = q.front();
q.pop();
if(tmp == label)
{
if(q.empty())
break;
else
{
level++;
q.push(label);
continue;
}
}
visits[tmp] = true;
if(graph[tmp].empty())
{
if(minnum > level)
{
minnum = level;
cnt = 1;
}
else if (minnum == level)
{
cnt++;
}
}
else
{
for(int i = 0;i < graph[tmp].size();i++)
{
if(!visits[graph[tmp][i]])
q.push(graph[tmp][i]);
}
}
}
return minnum - 1;
} int main()
{
int n;
double p,r;
while(cin >> n >> p >> r)
{
r /= 100;
for(int i = 0;i < n;i++)
{
int num;
cin >> num;
if(num == 0)
continue;
for(int j = 0;j < num;j++)
{
int tmp;
cin >> tmp;
graph[i].push_back(tmp);
}
}
int cnt = 0;
int len = bfs(cnt);
for(int i = 0;i < len;i++)
{
p *= static_cast<double>(1 + r);
}
cout << fixed << setprecision(4) << p << " " << cnt << endl;
}
}
PAT1106:Lowest Price in Supply Chain的更多相关文章
- [建树(非二叉树)] 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 ...
- 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 ...
- 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 ...
随机推荐
- ORACLE 多表关联 UPDATE 语句
为了方便起见,建立了以下简单模型,和构造了部分测试数据: 在某个业务受理子系统BSS中, SQL 代码 --客户资料表 create table customers ( customer_id num ...
- Salesforce开发入门
云计算风起云涌,已成势不可挡之势.公司好多项目都依托于云平台了,网络安全采用了zscaler,人力资源系统用的workday,我们case系统也用了salesforce,我自己也在用运行于Google ...
- Android官方技术文档翻译——新构建系统概述
本文译自Android官方技术文档<New Build System>,原文地址:http://tools.android.com/tech-docs/new-build-system. ...
- ffdshow 源代码分析 5: 位图覆盖滤镜(总结)
===================================================== ffdshow源代码分析系列文章列表: ffdshow 源代码分析 1: 整体结构 ffds ...
- Erlang Rebar 使用指南之一:入门篇
Erlang Rebar 使用指南之一:入门篇 全文目录: https://github.com/rebar/rebar/wiki 本章原文: https://github.com/rebar/reb ...
- 苹果新的编程语言 Swift 语言进阶(一)--综述
Swift 是苹果开发和提供的供开发IOS 和OS X应用的一门新的语言.Swift语言基于C 和Objective-C语言,除了提供C 和Objective-C语言具有的所有语法功能外,为了编程方便 ...
- EBS initialization parameters - Healthcheck
APPLIES TO: Oracle EBS Applications Performance - Version 11.5.10.2 to 12.2 [Release 11.5.10 to 12.2 ...
- 【Android 应用开发】BluetoothAdapter解析
这篇文章将会详细解析BluetoothAdapter的详细api, 包括隐藏方法, 每个常量含义. 一 BluetoothAdapter简介 1.继承关系 该类仅继承了Object类; 2.该类作用 ...
- 做自己的软件的Gallery(一)
先上效果图: 如图,android默认也有Gallery,很多软件在调用时,都是使用自己的Gallery,一方面好维护,另外一方面可以做优化.要做成以上样式,图片加载类起至关重要,一不小心,就好OOM ...
- Java数据类型之byte、char
Java 有8中基本数据类型,分别是byte.int.long.char.float.double.boolean. 1.byte.char的简单介绍 有时候总是搞不清byte.char,所以就现在好 ...