POJ 1584 计算几何
思路:
求一遍凸包
用三角形面积(叉积求一下)/边长
求出来高,跟半径比一比
坑点:凸包上三点共线
//By SiriusRen #include <cmath> #include <cstdio> #include <algorithm> using namespace std; #define eps 1e-9 const int N=1005; int n,top,k,f;double r; struct Point{double x,y;}point[N],tubao[N],cir; Point operator-(Point a,Point b){Point c;c.x=a.x-b.x,c.y=a.y-b.y;return c;} bool operator<(Point a,Point b){return abs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;} double chaji(Point a,Point b){return a.x*b.y-a.y*b.x;} double cross(Point a,Point b,Point c){return chaji(a-c,b-c);} double dis(Point a){return sqrt(a.x*a.x+a.y*a.y);} bool check(Point a,Point b){return abs(chaji(a-cir,b-cir))/dis(a-b)>r-eps;} int main(){ while(scanf("%d",&n)){ if(n<3)break;top=f=0; scanf("%lf%lf%lf",&r,&cir.x,&cir.y); for(int i=1;i<=n;i++)scanf("%lf%lf",&point[i].x,&point[i].y); sort(point+1,point+1+n); for(int i=1;i<=n;i++){ while(top>1&&cross(tubao[top],point[i],tubao[top-1])<-eps)top--; tubao[++top]=point[i]; }k=top; for(int i=n-1;i;i--){ while(top>k&&cross(tubao[top],point[i],tubao[top-1])<-eps)top--; tubao[++top]=point[i]; } if(top!=n+1){puts("HOLE IS ILL-FORMED");continue;} for(int i=1;i<=n;i++)if(!check(tubao[i],tubao[i+1]))f=1; for(int i=1;i<=n;i++) if(chaji(tubao[i+1]-tubao[i],cir-tubao[i])<0)f=1; printf("PEG WILL %sFIT\n",f?"NOT ":""); } }