POJ 1584 计算几何

Posted siriusren

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
",f?"NOT ":"");
    }
}

 

以上是关于POJ 1584 计算几何的主要内容,如果未能解决你的问题,请参考以下文章

计算几何专题

计算几何专题

POJ1556计算几何最短路

POJ 1385 计算几何 多边形重心

A Round Peg in a Ground Hole POJ - 1584(凸边形与圆相交)

POJ-2318 TOYS 计算几何 判断点在线段的位置