• POJ 1474 Video Surveillance(半平面交)


    题意:半平面交求多边形内核(我明明及的我之前是会用kuangbin第一份版平面交的,现在怎么就不会用了呢,补第二份代码)

    代码:

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #define eps 1e-10
    using namespace std;
    struct point{
        double x,y;
    }A[110],p[110],q[110];
    int N;
    void init(){
        for(int i=1;i<=N;++i){
            p[i]=A[i];
        }
        p[N+1]=p[1];p[0]=p[N];
    }
    void Get_equation(point p1,point p2,double &a,double &b,double &c)
    {
        a = p2.y - p1.y;
        b = p1.x - p2.x;
        c = p2.x*p1.y - p1.x*p2.y;
    }
    point Intersection(point p1,point p2,double a,double b,double c)
    {
        double u = fabs(a*p1.x + b*p1.y + c);
        double v = fabs(a*p2.x + b*p2.y + c);
        point t;
        t.x = (p1.x*v + p2.x*u)/(u+v);
        t.y = (p1.y*v + p2.y*u)/(u+v);
        return t;
    }
    void cut(double a,double b,double c,point p[],int &cnt){
        int tempcnt=0;
        for(int i=1;i<=cnt;++i){
            if(a*p[i].x+b*p[i].y+c>=0)q[++tempcnt]=p[i];
            else {
                if(a*p[i-1].x+b*p[i-1].y+c>0){
                    q[++tempcnt]=Intersection(p[i],p[i-1],a,b,c);
                }
                if(a*p[i+1].x+b*p[i+1].y+c>0){
                    q[++tempcnt]=Intersection(p[i],p[i+1],a,b,c);
                }
            }
        }
        for(int i=1;i<=tempcnt;++i){
            p[i]=q[i];
        }
        p[tempcnt+1]=p[1];p[0]=p[tempcnt];
        cnt=tempcnt;
    }
    
    
    void slove(){
        A[N+1]=A[1];
        init();
        int ans=N;
        for(int i=1;i<=N;++i){
            double a,b,c;
            Get_equation(A[i],A[i+1],a,b,c);
            cut(a,b,c,p,ans);
        }
        if(ans<=0)
            printf("Surveillance is impossible.
    ");
        else
            printf("Surveillance is possible.
    ");
    }
    int main()
    {
        int t=1,i;
        while(scanf("%d",&N),N){
            for(i=1;i<=N;++i){
                scanf("%lf%lf",&A[i].x,&A[i].y);
            }
            printf("Floor #%d
    ",t++);
            slove();
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    pyhton 163 email ssl attach file
    Database creation error: relation "ir_model" does not exist LINE 1: SELECT * FROM ir_model WHERE state='manual' ^
    爬虫心得
    WSL windows子系统ubuntu18.04建设自己的乌云
    WSL windwos 子系统 ubuntu18.04安装mysql
    python 163 email 554
    自定义的应用层协议(转)
    嵌入式杂谈之文件系统(转)
    linux VFS
    C++之保护和私有构造函数与析构函数
  • 原文地址:https://www.cnblogs.com/lalalatianlalu/p/8999415.html
Copyright © 2020-2023  润新知