题目链接:https://vjudge.net/problem/Gym-100520K
解题思路:
二分圆的半径,然后用半平面交解得是否有解,最后在有解的多边形中取最远的两个点看他们的距离是否超过直接,如果超过,那么以这两个点为圆心的两个圆就不会相交了。最远的点也就是枚举顶点两两的距离。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx = 2e2 + 10;
int n;
struct point
{
double x,y;
point operator - (point A)const
{
return point{x-A.x,y-A.y};
}
double operator * (point A)const
{
return x*A.y - A.x*y;
}
point operator + (point A)const
{
return point{x+A.x,y+A.y};
}
point operator * (double d)const
{
return point{x*d,y*d};
}
}s[mx],tmp[2],pue[mx],ans[2];
typedef point vec;
struct line
{
point p1,p2;
vec v;
double ang;
bool operator < (line A)const
{
return ang < A.ang;
}
}L[mx],lue[mx];
point GetP(point p,double angle,double r)
{
return point{p.x-sin(angle)*r,p.y+cos(angle)*r};
}
point Intersection(line a,line b)
{
/*double a1 = -a.v.y,a2 = -b.v.y;
double b1 = a.v.x,b2 = b.v.x;
double c1 = a.p1*a.p2,c2 = b.p1*b.p2;
double d = a.v*b.v;
return point{(b1*c2-b2*c1)/d,(a2*c1-a1*c2)/d};*/
vec u = a.p1 - b.p1;
double t = (b.v*u) / (a.v*b.v);
return a.p1 + a.v*t;
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
bool judge(int l,int r,double m)
{
double d = 0;
for(int i=l;i<=r;i++){
for(int j=i+1;j<=r;j++){
if(d<dist(pue[i],pue[j]))
{
d = dist(pue[i],pue[j]);
tmp[0] = pue[i],tmp[1] = pue[j];
}
}
}
if(d>=2*m) ans[0] = tmp[0],ans[1] = tmp[1];
return d >= 2*m;
}
bool Onright(line a,point b)
{
double d = a.v*point{b.x-a.p1.x,b.y-a.p1.y};
return d <= 0;
}
bool check(double m)
{
for(int i=0;i<n;i++){
double angle = atan2(s[(i+1)%n].y-s[i].y,s[(i+1)%n].x-s[i].x);
L[i].ang = angle;
L[i].p1 = GetP(s[i],angle,m);
L[i].p2 = GetP(s[(i+1)%n],angle,m);
//L[i].v = s[(i+1)%n] - s[i];
L[i].v = L[i].p2 - L[i].p1;
}
sort(L,L+n);
int tail = 0,head = 0;
lue[0] = L[0];
for(int i=1;i<n;i++){
while(head<tail&&Onright(L[i],pue[tail-1])) tail--;
while(head<tail&&Onright(L[i],pue[head])) head++;
pue[tail] = Intersection(L[i],lue[tail]);
lue[++tail] = L[i];
}
while(head<tail&&Onright(lue[head],pue[tail-1])) tail--;
pue[tail] = Intersection(lue[tail],lue[head]);
return judge(head,tail,m);
}
int main()
{
freopen("kabbalah.in ","r",stdin);
freopen("kabbalah.out","w",stdout);
while(scanf("%d",&n)&&n)
{
for(int i=0;i<n;i++){
scanf("%lf%lf",&s[i].x,&s[i].y);
}
double l = 0,r = 1e5;
for(int i=1;i<=100;i++)
{
double mid = (l+r)/2;
if(check(mid)) l = mid;
else r = mid;
}
printf("%.8lf\n",l);
printf("%.8lf %.8lf\n",ans[0].x,ans[0].y);
printf("%.8lf %.8lf\n",ans[1].x,ans[1].y);
}
return 0;
}
/*
5
0 0
3 4
4 6
6 10
10 18
*/