标签:pac can mat 计算 space ret 美丽 定义 std
题意:给$n$个点$(x_i,y_i)(0\leq x_i\leq w,0\leq y_i\leq h)$,一个点$(x,y)(0\leq x\leq w,0\leq y\leq h)$的美丽值定义为$\sqrt{(x-x_i)^2+(y-y_i)^2}$中的次小值,求最大美丽值
题解的做法是二分答案+圆求交,但那个好像挺难写的样子,退火我也不太会,还是得另辟蹊径
首先把$(0\leq x\leq w,0\leq y\leq h)$这个区域等分成$100$份,然后计算每份中心的美丽值,取美丽值最大的$10$份,再把这$10$份每份等分成$100$份,以此类推,重复$10$次基本就没有问题了
很暴力的想法,但实际上精度挺高,而且很好写
又是暴力碾标程系列23333
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct point{
double x,y,l;
point(double a=0.,double b=0.){
x=a;
y=b;
}
}s[2][1010],p[1010];
int f,n;
bool operator<(point a,point b){return a.l>b.l;}
double dis(point a,point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
void calc(point&q){
int i;
double f,s,t;
f=s=2e13;
for(i=1;i<=n;i++){
t=dis(p[i],q);
if(t<s)s=t;
if(f>s)swap(f,s);
}
q.l=s;
}
int main(){
int w,h,i,j,k,sp,c;
double ans,dx,dy;
scanf("%d%d%d",&w,&h,&n);
for(i=1;i<=n;i++){
scanf("%d%d",&j,&k);
p[i].x=j;
p[i].y=k;
}
c=0;
for(i=0;i<10;i++){
for(j=0;j<10;j++){
c++;
s[0][c]=point(w*(i+.5)*.1,h*(j+.5)*.1);
}
}
sp=10;
f=0;
dx=w*.05;
dy=h*.05;
while(sp--){
for(i=1;i<=c;i++)calc(s[f][i]);
sort(s[f]+1,s[f]+c+1);
ans=s[f][1].l;
dx*=.1;
dy*=.1;
c=0;
for(k=1;k<=10;k++){
for(i=0;i<10;i++){
for(j=0;j<10;j++){
c++;
s[f^1][c]=point(s[f][k].x+dx*(i*2.-9.),s[f][k].y+dy*(j*2.-9.));
}
}
}
f^=1;
}
printf("%.12lf",sqrt(ans));
}
[CF442E]Gena and Second Distance
标签:pac can mat 计算 space ret 美丽 定义 std
原文地址:http://www.cnblogs.com/jefflyy/p/8016339.html