lightoj 1260
两个多边形,问在职中穿行的圆的最大半径。
裸的点到线段距离,当模板了。
#include <cstdio> #include <cstring> #include <vector> #include <cmath> #include <stack> #include <cstdlib> #include <queue> #include <map> #include <iostream> #include <algorithm> #include <bits/stdc++.h> #include <queue> #include <ctime> using namespace std; struct Point { double x,y; }pa[110],pb[110]; double GetPointDistance(Point p1, Point p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } double GetNearestDistance(Point PA, Point PB, Point P3) { double a,b,c; a=GetPointDistance(PB,P3); if(a<=0.00001) return 0.0f; b=GetPointDistance(PA,P3); if(b<=0.00001) return 0.0f; c=GetPointDistance(PA,PB); if(c<=0.00001) return a;//如果PA和PB坐标相同,则退出函数,并返回距离 if(a*a>=b*b+c*c)//--------图3-------- return b; //如果是钝角返回b if(b*b>=a*a+c*c)//--------图4------- return a; //如果是钝角返回a double s=abs((PB.x-PA.x)*(P3.y-PA.y)-(P3.x-PA.x)*(PB.y-PA.y))/2.0; return 2*s/c; } int main() { int T,ncas=1; scanf ("%d",&T); while (T--) { memset(pa,0,sizeof(pa)); memset(pb,0,sizeof(pb)); int n; scanf ("%d",&n); for (int i=0;i<n;i++) { scanf ("%lf%lf",&pa[i].x,&pa[i].y); } int m; scanf ("%d",&m); for (int i=0;i<m;i++) { scanf ("%lf%lf",&pb[i].x,&pb[i].y); } pb[m]=pb[0]; double ans=0x7f7f7f7f; for (int i=0;i<n;i++) { for (int j=0;j<m;j++) { ans=min(ans,GetNearestDistance(pb[j],pb[j+1],pa[i])); } } printf ("Case %d: %.10f\n",ncas++,ans/2.0); } return 0; }