Poj 1474 video surveillance semi-plane intersection returns the existence of a polygon Kernel

Source: Internet
Author: User

There are many layers in a building. Each layer is a multi-polygon and you can see the full picture of each layer.


Idea: the semi-plane intersection solves the polygon kernel existence, bare question. Why didn't I write the data range ?.. Let me try again several times ..


Code:

#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 3010#define EPS 1e-8#define DCMP(a) (fabs(a) < EPS)using namespace std;struct Point{double x,y;Point(double _ = .0,double __ = .0):x(_),y(__) {}Point operator +(const Point &a)const {return Point(x + a.x,y + a.y);}Point operator -(const Point &a)const {return Point(x - a.x,y - a.y);}Point operator *(double a)const {return Point(x * a,y * a);}void Read() {scanf("%lf%lf",&x,&y);}}point[MAX],p[MAX];struct Line{Point p,v;double alpha;Line(Point _,Point __):p(_),v(__) {alpha = atan2(v.y,v.x);}Line() {}bool operator <(const Line &a)const {return alpha < a.alpha;}}line[MAX],q[MAX];int points;int lines;inline void Initialize(){lines = 0;}inline void MakeLine(const Point &a,const Point &b){line[++lines] = Line(a,b - a);}inline double Cross(const Point &a,const Point &b){return a.x * b.y - a.y * b.x;}inline bool OnLeft(const Line &l,const Point &p){return Cross(l.v,p - l.p) >= 0;}inline Point GetIntersection(const Line &a,const Line &b){Point u = a.p - b.p;double temp = Cross(b.v,u) / Cross(a.v,b.v);return a.p + a.v * temp;}inline bool HalfPlaneIntersection(){int front = 1,tail = 1;q[1] = line[1];for(int i = 2;i <= lines; ++i) {while(front < tail && !OnLeft(line[i],p[tail - 1]))--tail;while(front < tail && !OnLeft(line[i],p[front]))++front;if(DCMP(Cross(line[i].v,q[tail].v)))q[tail] = OnLeft(line[i],q[tail].p) ? q[tail]:line[i];elseq[++tail] = line[i];if(front < tail)p[tail - 1] = GetIntersection(q[tail],q[tail - 1]);}while(front < tail && !OnLeft(q[front],p[tail - 1]))--tail;if(tail - front <= 1)return false;return tail > front;}int main(){while(scanf("%d",&points),points) {Initialize();for(int i = 1;i <= points; ++i)point[i].Read();for(int i = points;i > 1; --i)MakeLine(point[i],point[i - 1]);MakeLine(point[1],point[points]);sort(line + 1,line + lines + 1);bool ans = HalfPlaneIntersection();static int T = 0;printf("Floor #%d\n",++T);if(ans)puts("Surveillance is possible.\n");elseputs("Surveillance is impossible.\n");}return 0;}


Poj 1474 video surveillance semi-plane intersection returns the existence of a polygon Kernel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.