描述 Description
在一块地上,有着n(1<=n<=2000) 头牛,输入n,再分别输入这n头牛的坐标(x,y)(1<=x<=100000,1<=y<=100000),如果第i头牛与第j头牛间的距离最近,那么输出i和j
10 | . . . . . . . 3 . . . . .
9 | . 1 . . 2 . . . . . . . .
8 | . . . . . . . . . . . . .
7 | . . . . . . . . . . 4 . .
6 | . . . . . . 9 . . . . . .
5 | . 8 . . . . . . . . . . .
4 | . . . . . 7 . . . . . . .
3 | . . . . . . . . . 5 . . .
2 | . . . . . . . . . . . . .
1 | . . . . 6 . . . . . . . .
0 ---------------------------
1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3
输入格式 InputFormat
第一行n下面n行,x,y
输出格式 OutputFormat
最近的两个点样例输入 SampleInput
9 2 9 5 9 8 10 11 7 10 3 5 1 6 4 2 5 7 6
样例输出 SampleOutput
7 9
数据范围和注释 Hint
usaco nov09 cu 第三道题解
水题。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
int n,ansx,ansy;
double x[2002],y[2002],map[2002][2002],minl=200000.0;
double count(int i,int j)
{
return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{double m=count(i,j);
if(m<minl) {ansx=i; ansy=j; minl=m;}
}
printf("%d %d",ansx,ansy);
return 0;
}