UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
解题报告
题意:
有一个旅游团如今去出游玩,如今有n个城市,m条路。因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟
思路:
求出发点到终点全部路其中最小值最大的那一条路。
求发可能有多种。最短路的松弛方式改掉是一种。最小生成树的解法也是一种(ps。prime和dijs就是这样子类似的)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;
int n,m,q,mmap[110][110];
void floyd() {
for(int k=0; k<n; k++)
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
mmap[i][j]=max(mmap[i][j],min(mmap[i][k],mmap[k][j]));
}
int main() {
int i,j,u,v,w,k=1;
while(~scanf("%d%d",&n,&m)) {
if(!n&&!m)break;
for(i=0; i<n; i++) {
for(j=0; j<n; j++)
mmap[i][j]=0;
}
for(i=0; i<m; i++) {
scanf("%d%d%d",&u,&v,&w);
mmap[u-1][v-1]=mmap[v-1][u-1]=w;
}
floyd();
scanf("%d%d%d",&u,&v,&w);
int ans=0,num=mmap[u-1][v-1]-1;
ans=ceil((double)w/num);
printf("Scenario #%d\n",k++);
printf("Minimum Number of Trips = %d\n\n",ans);
}
return 0;
}
The Tourist Guide
Input: standard input
Output: standard output
Mr. G. works as a tourist guide. His current assignment is to take some tourists from one city to another. Some two-way roads connect the cities. For each pair of neighboring cities there is a bus service that runs only between those two cities and uses
the road that directly connects them. Each bus service has a limit on the maximum number of passengers it can carry. Mr. G. has a map showing the cities and the roads connecting them. He also has the information regarding each bus service. He understands that
it may not always be possible for him to take all the tourists to the destination city in a single trip. For example, consider the following road map of 7 cities. The edges connecting the cities represent the roads and the number written on each edge indicates
the passenger limit of the bus service that runs on that road.
Now, if he wants to take 99 tourists from city 1 to city 7, he will require at least 5 trips, since he has to ride the bus with each group, and the route he should take is : 1 - 2 - 4 - 7.
But, Mr. G. finds it difficult to find the best route all by himself so that he may be able to take all the tourists to the destination city in minimum number of trips. So, he seeks your help.
Input
The input will contain one or more test cases. The first line of each test case will contain two integers: N (N<= 100) and R representing respectively the number of cities and the number of road segments. Then R lines will follow
each containing three integers: C1, C2 andP. C1 and C2 are
the city numbers and P (P> 1) is the limit on the maximum number of passengers to be carried by the bus service between the two cities. City numbers are positive integers ranging from 1 to N. The (R + 1)-th line will contain three
integers: S, D andT representing respectively the starting city, the destination city and the number of tourists to be guided.
The input will end with two zeroes for N and R.
Output
For each test case in the input first output the scenario number. Then output the minimum number of trips required for this case on a separate line. Print a blank line after the output of each test case.
Sample Input
7 10
1 2 30
1 3 15
1 4 10
2 4 25
2 5 60
3 4 40
3 6 20
4 7 35
5 7 20
6 7 30
1 7 99
0 0
Sample Output
Scenario #1
Minimum Number of Trips = 5
UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)的更多相关文章
- UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)
解题报告 题意: 求全部路中最大分贝最小的路. 思路: 类似floyd算法的思想.u->v能够有另外一点k.通过u->k->v来走,拿u->k和k->v的最大值和u-&g ...
- UVa567_Risk(最短路)(小白书图论专题)
解题报告 option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=508"& ...
- UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)
解题报告 题意: n个插头m个设备k种转换器.求有多少设备无法插入. 思路: 定义源点和汇点,源点和设备相连,容量为1. 汇点和插头相连,容量也为1. 插头和设备相连,容量也为1. 可转换插头相连,容 ...
- UVa563_Crimewave(网络流/最大流)(小白书图论专题)
解题报告 思路: 要求抢劫银行的伙伴(想了N多名词来形容,强盗,贼匪,小偷,sad.都认为不合适)不在同一个路口相碰面,能够把点拆成两个点,一个入点.一个出点. 再设计源点s连向银行位置.再矩阵外围套 ...
- UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...
- UVa409_Excuses, Excuses!(小白书字符串专题)
解题报告 题意: 找包括单词最多的串.有多个按顺序输出 思路: 字典树爆. #include <cstdio> #include <cstring> #include < ...
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- [uva] 10099 - The Tourist Guide
10099 - The Tourist Guide 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...
- ACM/ICPC 之 最短路-Floyd+SPFA(BFS)+DP(ZOJ1232)
这是一道非常好的题目,融合了很多知识点. ZOJ1232-Adventrue of Super Mario 这一题折磨我挺长时间的,不过最后做出来非常开心啊,哇咔咔咔 题意就不累述了,注释有写,难点在 ...
随机推荐
- javolution-core-java-6.1.0.jar 的使用
官方网址:http://javolution.org/apidocs/javolution/io/Struct.html 第一步:导包 第二步:创建继承的结构体 结构体定义如下所示: public c ...
- VMware三种网络模式组网(转)
VMware为我们提供了三种网络工作模式,它们分别是:Bridged(桥接模式).NAT(网络地址转换模式).Host-Only(仅主机模式). 打开VMware虚拟机,我们可以在选项栏的“编辑”下的 ...
- Zookeeper api增删改查节点
Exists - 检查Znode的存在 ZooKeeper类提供了 exists 方法来检查znode的存在.如果指定的znode存在,则返回一个znode的元数据.exists方法的签名如下: ex ...
- 修改nvm镜像地址
最近几个项目切换开发要求Node版本不一样,没法运行.需要用nvm或n等来管理node版本,选谁见仁见智了,反正我选了nvm. 下载个node慢得要死,等半天结果还失败,真是窝火.官方文档又详细过了一 ...
- javascript数组及操作方法
数组及操作方法 数组就是一组数据的集合,javascript中,数组里面的数据可以是不同类型的. 定义数组的方法 //对象的实例创建 var aList = new Array(1,2,3); //直 ...
- D3.js系列——比例尺和坐标轴
比例尺是 D3 中很重要的一个概念.绘制图形时直接用数值的大小来代表像素不是一种好方法,本章正是要解决此问题. 一.为什么需要比例尺 上一章制作了一个柱形图,当时有一个数组,绘图时,直接使用 250 ...
- Java笔记2:Eclipse编写第一个Java程序
1 下载并安装jdk 2 下载较新版本的eclipse,eclipse都是非安装版的,解压缩即可. 3 双击eclipse.exe,打开elipse软件 4 FileàNewàProject 5 选择 ...
- Oracle Database Link 的创建和使用小见
假设:需要从数据库db_a通过db_link连接到db_b查询数据库b的部分相关信息 前提条件: 数据库a账户需要有创建dblink的权限,如果没有可以使用dba账户赋权限 grant CREATE ...
- Java中的值传递与“引用传递”
首先,Java没有 引用传递 这么一说. Java仅仅有值传递.传递的都是值,基本数据类型传递的是值.引用类型传递的是地址值. 我来理一下这当中宛如米线跟米面绞在一起了,再跟粉丝混在一起的关系. 好的 ...
- Servlet——简单用户登录实例+http协议解析
编写项目.用户登录系统1.0版本号 登录界面Servlet: package com.gavin.view; import java.io.IOException; import java.io.Pr ...