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. Swift的基础之UILabel控件

    对于UILabel的相关内容,其他控件可以相似创建 //设置全局变量,将下面的 let 去掉,然后替换即可     //var myLabel = UILabel();     //系统生成的view ...

  2. 《java入门第一季》之面向对象(final关键字)

    /* final可以修饰类,方法,变量 特点: final(可以修饰类),该(类)(不能被继承).一旦修饰了一个类,这个类就不能被继承了! final以修饰方法,该方法可以被继承但是不能被重写.(覆盖 ...

  3. 【65】Mybatis详解

    Mybatis介绍 MyBatis是一款一流的支持自定义SQL.存储过程和高级映射的持久化框架.MyBatis几乎消除了所有的JDBC代码,也基本不需要手工去设置参数和获取检索结果.MyBatis能够 ...

  4. ITU-T Technical Paper: 测量QoS的基本网络模型

    本文翻译自ITU-T的Technical Paper:<How to increase QoS/QoE of IP-based platform(s) to regionally agreed ...

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

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

  6. Android 实现高仿iOS桌面效果之可拖动的GridView(上)

    转载请标明出处:http://blog.csdn.net/sk719887916/article/details/40074663,作者:skay      最近项目中遇到一个LIstview的拖动效 ...

  7. MfgTool (i.MX53)使用

    1 Introduction The MfgTool is a manufacturing tool from Freescale that runs under Windows. It is des ...

  8. 解决水平ListView在ScrollView中出现的滑动冲突

      解决的问题有两个:  1)实现水平滑动的ListView.重写AdapterView,上代码: package com.liucanwen.horizontallistview.view; imp ...

  9. mybatis ---- 级联查询 一对多 (集合映射)

    关联有嵌套查询和嵌套结果两种方式,本文是按照嵌套结果这种方式来说明的 上一章介绍了多对一的关系,用到了<association></association>,这是一个复杂类型的 ...

  10. ubuntu12.04:Mysql数据库:手动安装

    首先到mysql的下载中心上下载最新的tar.gz包: 1.在浏览器中输入http://www.mysql.com/downloads/ 进入mysql的下载中心,在这里有使用mysql开发的一些工具 ...