码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1584 计算几何

时间:2018-07-28 18:22:29      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:main   半径   amp   class   sort   can   凸包   print   fine   

思路:

求一遍凸包

用三角形面积(叉积求一下)/边长

求出来高,跟半径比一比

坑点:凸包上三点共线

//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 ":"");
    }
}

 

POJ 1584 计算几何

标签:main   半径   amp   class   sort   can   凸包   print   fine   

原文地址:https://www.cnblogs.com/SiriusRen/p/9382591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!