题目链接:https://vjudge.net/problem/Gym-101170K
解题思路:
由于题目前提,所以每个夹角肯定可以夹住一个圆,然后再判断是内角还是外角。还有圆不能越出边框。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mx = 2e3 + 10;
int n,m;
struct node
{
double x,y;
node operator - (node A)const{ return node{x-A.x,y-A.y}; }
node operator + (node A)const{ return node{x+A.x,y+A.y}; }
node operator * (double d)const{ return node{x*d,y*d}; }
node operator / (double d)const{ return node{x/d,y/d}; }
double operator * (node A)const{ return x*A.x + y*A.y; }
}s[mx],ans[mx];
double dist(node A){ return sqrt(A.x*A.x+A.y*A.y); }
node getDot(double c1,node A,node B)
{
A = A / dist(A);
B = B / dist(B);
node F = (A+B)/2.0;
F = F / dist(F);
return F*c1;
}
double cross(node p1,node p2){ return p1.x*p2.y - p2.x*p1.y; }
double segdist(node w,node A,node B)//点到线段距离
{
if((w-A)*(B-A)>=0&&(w-B)*(A-B)>=0) return fabs(cross(w-A,B-A))/dist(B-A);
return min(dist(w-A),dist(w-B));
}
bool check(node A){
for(int i=0;i<n;i++)
if(segdist(A,s[i],s[(i+1)%n])<4000) return 1;
return 0;
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf%lf",&s[i].x,&s[i].y);
}
for(int i=0;i<n;i++){
int l = i,mid = (i+1)%n,r = (i+2)%n;
node A = s[l] - s[mid];
node B = s[r] - s[mid];
if(cross(A,B)<0) continue;
double angle = A*B / (dist(A)*dist(B));
angle = acos(angle)/2;
ans[m++] = getDot(4000.1/sin(angle),A,B)+s[mid];
if(check(ans[m-1])) m--;
}
for(int i=0;i<m;i++){
for(int j=i+1;j<m;j++){
if(dist(ans[j]-ans[i])>=8000){
printf("%.6lf %.6lf\n",ans[i].x,ans[i].y);
printf("%.6lf %.6lf\n",ans[j].x,ans[j].y);
return 0;
}
}
}
puts("impossible");
return 0;
}