着弹点
Time Limit:1000MSMemory Limit:30000KB
Total Submit:482Accepted:62
Description
炮兵某部进行实弹射击,对一个平面区域里连续开炮,得到了很多的弹坑.当射击完成后,作为技术人员的你,
想要得到一个重要的参数,就是相隔距离最大的炮弹着弹点的距离.
Input
多组数据,每组第一行n代表点数,接着n行为着弹点的坐标,坐标为正整数,不超过1000000。
2<=n<=30000。
Output
每组一行,求出相隔距离最大的两个着弹点之间的距离,保留2位小数
Sample Input
3
1 2
3 4
5 6
Sample Output
5.66
有时AC也靠rp的,虽然这样很没节操。。
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
struct point{
double x,y;
};
bool cmp1(point a,point b){
return a.x < b.x;
}
bool cmp2(point a,point b){
return a.y < b.y;
}
point p[30005];
double dis(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i = 0;i < n ;i ++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
double ans = 0.0;
sort(p,p+n,cmp1);
for(int i = 0;i < n && i < 3000;i ++){
for(int j = n-1;j >=0 && j >= n-3001; j--){
ans = max(ans,dis(p[i],p[j]));
}
}
sort(p,p+n,cmp2);
for(int i = 0;i < n && i < 3000;i ++){
for(int j = n-1;j >= 0 && j >= n-3001; j--){
ans = max(ans,dis(p[i],p[j]));
}
}
printf("%.2lf\n",ans);
}
return 0;
}