Farmer John has a number of pastures on his farm. Cow paths connect some pastures with certain other pastures, forming a field. But, at the present time, you can find at least two pastures that cannot be connected by any sequence of cow paths, thus partitioning Farmer John's farm into multiple fields.
Farmer John would like add a single a cow path between one pair of pastures using the constraints below.
A field's `diameter' is defined to be the largest distance of all the shortest walks between any pair of pastures in the field. Consider the field below with five pastures, located at the points shown, and cow paths marked by lines:
15,15 20,15 D E *-------* | _/| | _/ | | _/ | |/ | *--------*-------* A B C 10,10 15,10 20,10
The `diameter' of this field is approximately 12.07106, since the longest of the set of shortest paths between pairs of pastures is the path from A to E (which includes the point set {A,B,E}). No other pair of pastures in this field is farther apart when connected by an optimal sequence of cow paths.
Suppose another field on the same plane is connected by cow paths as follows:
*F 30,15 / _/ _/ / *------ G H 25,10 30,10
In the scenario of just two fields on his farm, Farmer John would add a cow path between a point in each of these two fields (namely point sets {A,B,C,D,E} and {F,G,H}) so that the joined set of pastures {A,B,C,D,E,F,G,H} has the smallest possible diameter.
Note that cow paths do not connect just because they cross each other; they only connect at listed points.
The input contains the pastures, their locations, and a symmetric "adjacency" matrix that tells whether pastures are connected by cow paths. Pastures are not considered to be connected to themselves. Here's one annotated adjacency list for the pasture {A,B,C,D,E,F,G,H} as shown above:
A B C D E F G H A 0 1 0 0 0 0 0 0 B 1 0 1 1 1 0 0 0 C 0 1 0 0 1 0 0 0 D 0 1 0 0 1 0 0 0 E 0 1 1 1 0 0 0 0 F 0 0 0 0 0 0 1 0 G 0 0 0 0 0 1 0 1 H 0 0 0 0 0 0 1 0
Other equivalent adjacency lists might permute the rows and columns by using some order other than alphabetical to show the point connections. The input data contains no names for the points.
The input will contain at least two pastures that are not connected by any sequence of cow paths.
Find a way to connect exactly two pastures in the input with a cow path so that the new combined field has the smallest possible diameter of any possible pair of connected pastures. Output that smallest possible diameter.
PROGRAM NAME: cowtour
INPUT FORMAT
Line 1: | An integer, N (1 <= N <= 150), the number of pastures |
Line 2-N+1: | Two integers, X and Y (0 <= X ,Y<= 100000), that denote that X,Y grid location of the pastures; all input pastures are unique. |
Line N+2-2*N+1: | lines, each containing N digits (0 or 1) that represent the adjacency matrix as described above, where the rows' and columns' indices are in order of the points just listed. |
SAMPLE INPUT (file cowtour.in)
8 10 10 15 10 20 10 15 15 20 15 30 15 25 10 30 10 01000000 10111000 01001000 01001000 01110000 00000010 00000101 00000010
OUTPUT FORMAT
The output consists of a single line with the diameter of the newly joined pastures. Print the answer to exactly six decimal places. Do not perform any special rounding on your output.
SAMPLE OUTPUT (file cowtour.out)
22.071068
题意:
给出 N(1 ~ 150),代表有 N 个坐标点(X,Y)(0 ~ 100000),后给出 N X N 的邻接矩阵,代表图的连接情况( 0 代表不相连,1 代表相连)。图明确只有两个不相连的连通块,问如何当且仅当增加一条边,使任何点对间的最短路中的最大值最小。输出这个最小数,保留六位小数。
思路:
最短路 + Floyd。先 Floyd 预处理好所有点对之间的最短路,后枚举两个点,这两个点不相连。增加这条边后,故( 第一个连通块任意两点间的最短路 + 增加边边长 + 第二个连通块任意两点间的最短路) 也为最短路,找到连接后所有点对最短路的最大值。每次枚举的最大值中找一个最小的,当找出这个最小值,还要与原来未连接的时候的最短路的最大值比较。最后得出的这个值即为最终结果的最大值。
AC:
/* TASK:cowtour LANG:C++ ID:sum-g1 */ #include <stdio.h> #include <string.h> #include <cmath> #include <algorithm> #define INF 99999999 using namespace std; typedef struct { double x,y; }node; int n; node no[155]; double w[155][155]; char state[155][155]; double max_dis; double dis (double x1,double y1,double x2,double y2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } void floyd () { for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if(w[i][k] < INF && w[k][j] < INF && w[i][j] > w[i][k] + w[k][j]) w[i][j] = w[i][k] + w[k][j]; } void init () { for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { if (state[i][j] == '1') w[i][j] = dis(no[i].x,no[i].y,no[j].x,no[j].y); else w[i][j] = INF; if(i == j) w[i][j] = 0; } } double make_max (int s,int e,double dis) { double max_now = -1; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if(w[i][s] < INF && w[e][j] < INF) max_now = max(max_now,w[i][s] + w[e][j] + dis); return max_now; } int main() { freopen("cowtour.in","r",stdin); freopen("cowtour.out","w",stdout); scanf("%d",&n); for (int i = 1; i <= n; ++i) scanf("%lf%lf",&no[i].x,&no[i].y); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) scanf(" %c",&state[i][j]); } init(); floyd(); max_dis = -1; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if(w[i][j] < INF) max_dis = max(max_dis,w[i][j]); double min_dis = INF; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if(w[i][j] == INF) { double change = dis(no[i].x,no[i].y,no[j].x,no[j].y); min_dis = min(min_dis,make_max(i,j,change)); } min_dis = max(min_dis,max_dis); printf("%f\n",min_dis); return 0; }
相关推荐
"Web Tours 1.0.7z" 是一个软件安装包的压缩文件,采用7-Zip格式进行压缩,主要用于Web Tours 1.0版本的安装。7-Zip是一种开源的压缩工具,以其高效率和对多种压缩格式的支持而受到用户欢迎。在软件开发和测试领域,...
Web Tours 1.0安装包下载 Web Tours是惠普 loadrunner 自带的一个飞机订票系统网站,它是一款基于ASP.net平台的网站,基于先进的.NET Framework,默认支持SqlServer数据库、Access、Mysq等多种数据库,这是基于ie、...
hp web tours 分析
《LoadRunner WebTours 示例深度解析》 LoadRunner是一款由HP公司开发的强大的负载和性能测试工具,广泛应用于企业级应用系统的性能测试。本示例“WebTours”旨在为初学者提供一个无需安装完整LoadRunner环境即可...
由于今天花了时间去移动(Loadruner自带的WebTours例子程序)到其他的电脑上,方便练习Loadrunner,偷懒。很久没有动部署的东西了,解决问题思路有些迟钝,现在把应有思路的做一个小的整理。部署高手请略过。 由于...
《LoadRunner 12在WebTours订票系统中的应用详解》 LoadRunner,作为业界知名的压力和性能测试工具,是HP(现为Micro Focus)公司推出的一款强大测试平台,尤其在软件测试领域中占据重要地位。在本案例中,我们将...
【QTP Mercury Tours 网站安装程序】 QuickTest Professional(QTP)是HP公司推出的一款功能强大的自动化测试工具,主要用于软件的功能测试和回归测试。Mercury Tours 是一个示例应用,常常被用作QTP的学习平台,...
【标题】"LoadRunner11版WebTours"是一个经典的性能测试案例,它涉及的是使用HP LoadRunner 11工具对一个模拟的飞机订票系统进行性能测试的过程。这个系统是LoadRunner自带的示例应用,用于教学和实践性能测试的基本...
今天安装了Loadrunner9.0后,发现打开LR示例页面的时候会显示如下错误: Internalerror:yourrequestwasunsuccessful CannotcreateCGIprocess–programnotfound 解决方法: 打开WebTours文件夹下的run.bat,...
《Mercury Tours Web Application与LoadRunner性能测试详解》 Mercury Tours Web Application是一款早期用于LoadRunner性能测试训练的示例应用程序。它为用户提供了一个模拟在线旅游预订系统的平台,旨在帮助学习者...
Web Tours 1.0安装包下载 Web Tours是HP loadrunner 自带的一个飞机订票系统网站,它是一款基于ASP.net平台的网站,基于先进的.NET Framework,默认支持SqlServer数据库、Access、Mysq等多种数据库,这是基于ie、...
本文将详细讨论“webtours案例”中的“检查点”和“事务”概念,以及如何利用LoadRunner来设置这两个关键元素。 首先,我们来看“webtours案例”。这是一个模拟旅游网站操作的场景,可能包括浏览旅游套餐、预订、...
WEB-Tours 订票系统性能测试报告 本报告对 WEB-Tours 订票系统的性能测试进行了详细的说明和分析。该系统是航空公司机票信息治理的重要组成部分,随着业务系统的发展,系统的性能问题逐渐成为了关注的焦点。因此,...
webtours_login_success.jmx
"WebTours测试计划" 测试计划是对软件应用程序的测试,以确保其满足预期的需求和标准。以下是WebTours测试计划的摘要信息: 测试目的:确保WebTours应用程序满足预期的需求和标准,确保系统的稳定性、安全性和可靠...
### Webtours安装详细步骤与知识点解析 #### 一、安装前准备 在开始Webtours的安装之前,我们需要确保已经准备好以下环境和工具: 1. **Java Development Kit (JDK) 安装**:Webtours需要JDK的支持来运行其内部的...
LoadRuner12.6实战项目,Web Tours1.0资源,有需自取,没有积分限制,原下载地址:https://marketplace.microfocus.com/appdelivery/content/web-tours-sample-application
早期LoadRunner培训时使用的Mercury Tours Web应用,太大了所以分两部分。Enjoy it!