1106. Lowest Price in Supply Chain (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

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

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

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

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

  3. 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 ...

  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. Android帧布局(Frame Layout)

    Android帧布局(Frame Layout) FrameLayout是最简单的一个布局管理器.FrameLayout为每个加入其中的组件创建一个空白区域(一帧),这些组件根据layout_grav ...

  2. U盘无法安装win10提示Your PC/Device needs to be repaired

    前一阵子把笔记本自带的win8升级到8.1,又升级到win10. 差不多有一个月没有开机,前几天开机后进不了系统,出现如下图的提示.买电脑自带的win8是正版的,但升级到win10后就过期了,也真是坑 ...

  3. 生产者消费者的java实现

    先看最简单的,也就是缓冲区的容量为1 缓冲区容量为1 import java.util.List; public class ProducerAndConsumer2 { static class A ...

  4. VC工程的.gitignore模板

    VC工程的.gitignore模板 文件内容如下: #====================================== # .gitignore # # 2015-01-09 create ...

  5. LeetCode之“动态规划”:Minimum Path Sum && Unique Paths && Unique Paths II

    之所以将这三道题放在一起,是因为这三道题非常类似. 1. Minimum Path Sum 题目链接 题目要求: Given a m x n grid filled with non-negative ...

  6. LeetCode之“字符串”:Valid Number(由此引发的对正则表达式的学习)

    题目链接 题目要求: Validate if a given string is numeric. Some examples: "0" => true " 0.1 ...

  7. Systemc在VC++2010安装方法及如何在VC++2010运行Noxim模拟器

    Systemc在VC++2010的安装方法可以参考文档"Systemc with Microsoft Visual Studio 2008.pdf".本文档可以在"htt ...

  8. Libevent库学习笔记

    Libevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,Libevent在底层select.pool.kqueue和epoll等机制基础上,封装出一致的事件接口.可 ...

  9. svn中出现各种感叹号说明

    黄色感叹号(有冲突): --这是有冲突了,冲突就是说你对某个文件进行了修改,别人也对这个文件进行了修改,别人抢在你提交之前先提交了,这时你再提交就会被提示发生冲突,而不允许你提交,防止你的提交覆盖了别 ...

  10. 译文:ovs+dpdk中的“vHost User NUMA感知”特性

    本文描述了"vHost User NUMA感知"的概念,该特性的测试表现,以及该特性为ovs+dpdk带来的性能提升.本文的目标受众是那些希望了解ovs+dpdk底层细节的人,如果 ...