zoukankan      html  css  js  c++  java
  • 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 ":"");
        }
    }
  • 相关阅读:
    k8s之docker被屏蔽后下载方法
    代码合并工具Beyond Compare的使用技巧
    (转)设计模式——观察者模式
    notepad问题汇总
    个人构建问题
    内部git常用总结
    (转)动态规划算法—买卖股票的最佳时机系列
    (转)java中引用传递和值传递
    互联网面试题
    (转)UML类图与类的关系详解
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/9382591.html
Copyright © 2011-2022 走看看