Logu P1522 Cattle Travel Cow Tours__noip

Source: Internet
Author: User
P1522 Cattle Travel Cow Tours
First of all, the translation is very bad, or to see the original is better.
http://blog.csdn.net/supersnow0622/article/details/9763979 This article is well written, excerpt as follows:
Analysis: The first thing to connect the two pastoral areas of the road, before is not connected. Secondly, after the two pastoral areas have been repaired,
The farthest distance between the two pastoral areas is the smallest. As a matter of fact, it would be nice to enumerate the two pastoral areas that are arbitrarily disconnected and calculate the farthest distance in this case.
And then find the minimum distance in these farthest distances (the minimum of the required radius of the topic) is the request.
The key is to find the radius of the ranch after the two unconnected pastoral areas have been repaired. Suppose that the D of one pastoral species is connected with the F in the two pastoral area,
Think about whether the radius of the ranch is equal to the distance from D to the distance between +d and F, the distance from the farthest point to F.
This approach is to meet the title of the pasture radius is the farthest distance between the two points.
So the idea soon came out:
1. Calculate the distance between any two points with floyed
2. Calculate the farthest distance between each point and the other point
3. Calculate the radius of the pasture after repairing any two unconnected points.
Http://www.xuebuyuan.com/1457314.html This article gives the original English title, read down, with Chinese meaning, understand the topic.
Http://www.nocow.cn/index.php/USACO/cowtour According to this article, understand, why
So we just need to calculate the diameter of the new contiguous block, then put it together with the diameter of all the blocks, and take the maximum diameter.
Suddenly to why take the largest diameter, and doubts, think for 3 hours, think Impassability, temporarily put aside.
The problem of foreigners, and China's problems, there are indeed cultural differences. Sigh.
In the process of coding, it is true that the Logu sample input data is problematic. Looked up a pass, found no problem, the data format is the case. A toss.
#include <stdio.h>
#include <string.h>
#include <math.h>//, the header file must be submitted in C + + form.
#define INF 1000000
int x[150+10],y[150+10];
Double A[150+10][150+10],d[150+10],mind=inf;
Char s[200];
Double dis (int x1,int y1,int x2,int y2) {
return sqrt (double) (x1-x2) * (X1-X2) + (double) (y1-y2) * (y1-y2));/Don't forget to turn around, it's easy to overflow 100000*100000
}
int main () {
int i,j,k,n,w;
Memset (d,0,sizeof (d));
scanf ("%d", &n);
for (i=1;i<=n;i++)
scanf ("%d%d", &x[i],&y[i]);
for (i=1;i<=n;i++) {
scanf ("%s", s+1);
for (j=1;j<=n;j++) {
if (i!=j) {
if (s[j]== ' 0 ')
A[i][j]=a[i][j]=inf;
else{
A[i][j]=a[j][i]=dis (X[i],y[i],x[j],y[j]);
}
}else
a[i][j]=0;
}
}
for (k=1;k<=n;k++)//floyd algorithm
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (A[i][j]>a[i][k]+a[k][j])
A[I][J]=A[I][K]+A[K][J];
for (i=1;i<=n;i++)//connected block to find the maximum value
for (j=1;j<=n;j++)
if (A[i][j]<inf&&a[i][j]>d[i])
D[I]=A[I][J];
for (i=1;i<=n;i++)//Connect two pastoral areas, find the minimum value.
for (j=1;j<=n;j++)
if (A[i][j]==inf&&mind>d[i]+d[j]+dis (X[i],y[i],x[j],y[j]))
Mind=d[i]+d[j]+dis (X[i],y[i],x[j],y[j]);
for (i=1;i<=n;i++)//Here do not understand why to find the maximum value. When the level is high, look at this problem again. 2017-6-20 21:23
if (Mind<d[i])
Mind=d[i];
printf ("%.6lf\n", MinD);//1 here written printf ("%d\n", MinD); low-level error
return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.