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. Python3.4 + Django1.7.7 搭建简单的表单并提交

    后面还有一个问题,是我把txt生成了,但是网页没有返回我还不知道,现在怎么直接返回txt并且展示出来txt 的内容,希望大牛不吝赐教 首先有一个问题 django1.7之前,这样用: HttpResp ...

  2. 一个很不错的支持Ext JS 4的上传按钮

    以前经常使用的swfUpload,自从2010年开始到现在,很久没更新了.而这几年,flash版本已经换了好多个,所以决定抛弃swfupload,使用新找到的上传按钮. 新的上传按钮由harrydel ...

  3. 《java入门第一季》之面向对象(面向对象案例详解)

    通过几个小案例理重新回顾一下前面所写的内容,对面向对象的理解更加深刻的目的: 案例一: /* 需求: 定义一个员工类,自己分析出几个成员, 然后给出成员变量,构造方法,getXxx()/setXxx( ...

  4. linux上 java 使用 javasqlite

    linux上 java 使用 javasqlite http://www.ch-werner.de/javasqlite/ 1) 下载: http://www.ch-werner.de/javasql ...

  5. Mondrian Schema workbench工作界面 简介(实在懒得写,居然有人弄了,收藏了)

    转自:http://hi.baidu.com/dinguangx/item/37e78be29aebc1adcf2d4f89 Schema Schema 定义了一个多维数据库.包含了一个逻辑模型,而这 ...

  6. C语言之鞍点的查找

    鞍点(Saddle point)在微分方程中,沿着某一方向是稳定的,另一条方向是不稳定的奇点,叫做鞍点.在泛函中,既不是极大值点也不是极小值点的临界点,叫做鞍点.在矩阵中,一个数在所在行中是最大值,在 ...

  7. Android Camera开发系列(上)——Camera的基本调用与实现拍照功能以及获取拍照图片加载大图片

    Android Camera开发系列(上)--Camera的基本调用与实现拍照功能以及获取拍照图片加载大图片 最近也是在搞个破相机,兼容性那叫一个不忍直视啊,于是自己翻阅了一些基本的资料,自己实现了一 ...

  8. Linux - 动态(Dynamic)与静态(Static)函数库

    首先我们要知道的是,函式库的类型有哪些?依据函式库被使用的类型而分为两大类,分别是静态 (Static) 与动态 (Dynamic) 函式库两类. 静态函式库的特色: 扩展名:(扩展名为 .a)   ...

  9. 64位linux下安装ps模拟器ePSxe

    早就想在爱机上玩ps游戏,特别是彩京的1945一代和非常经典的实况足球2002版.在ubuntu64位下可以通过wine模拟的方式运行windows版的ePSxe,但是总觉得差些呢?非原生啊!网上搜了 ...

  10. 从小故事来谈nginx负载均衡

    负载均衡 负载均衡是任何一个有一定规模的互联网企业都会考虑的问题,负载方式很多,有依靠硬件实现的,也有依靠软件实现负载的. 今天来聊聊使用软件来负载的方式 你可能听过各自负载的方式,比如常见的ngin ...