描述 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 |
輸入格式 Input Format | |||
第一行n 下面n行,x,y |
|||
輸出格式 Output Format | |||
最近的兩個點 | |||
樣例輸入 Sample Input [複製數據] | |||
樣例輸出 Sample Output [複製數據] | |||
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long x[2050],y[2050];
int main ()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
long long min=((long long)1<<63)-1; //最大數的表示方法
int a=1,b=1;
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
{
long long l=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
if(l<min)
{
min=l;
a=i;
b=j;
}
}
cout<<a<<' '<<b<<endl;
return 0;
}