"POJ" 1279

Source: Internet
Author: User

http://poj.org/submit?problem_id=1279

Test instructions: To an n-point polygon, n<=1500, to see the area of points on all polygons within the polygon.

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long Long LL; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define For2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= ( a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) # Define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (! x) puts ("error"): 0) #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) inline const int Getint () {int r=0, k=1; Char c=g Etchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }const double eps=1e-6;const int n=1515;int dcmp (double x) {return ABS (x) <eps?0: (x<0?-1:1); }struct IP {double x, y; IP (double _x=0, double _y=0): X (_x), Y (_y) {}};typedef IP iv;iv operator-(IP A, IP b) {Retu RN IV (a.x-b.x, A.Y-B.Y); }IP operator + (IP A, IV b) {return IP (a.x+b.x, a.y+b.y);} IV operator * (IP A, double D) {return IV (A.x*d, a.y*d);} Double Cross (iv A, IV b) {return a.x*b.y-a.y*b.x;} Double angle (IV &a) {return atan2 (A.Y, a.x);} struct IL {iV v; IP p;double ang;void Set (IP A, IP b) {p=a; v=b-a; Ang=angle (v);} BOOL operator< (const IL &b) const {return ang<b.ang;}}; IP LLi (Il &a, il &b) {static IV u;static double T;u=a.p-b.p;t=cross (B.V, u)/cross (A.V, B.V); return a.p+a.v*t;} BOOL OnL (IP &a, IL &l) {return dcmp (cross (L.V, A-L.P)) >0;} BOOL Half (IL *line, int n, IP *s, int &cnt) {static IL a[n], q[n];static iP b[n];static int front, tail;memcpy (A, line , sizeof (IL) * (n+1)), sort (a+1, a+1+n), Q[front=tail=0]=a[1];for1 (i, 2, N) {while (Front!=tail &&!onl (B[tail-1], A[i])--tail;while(Front!=tail &&!onl (B[front], a[i]) ++front;q[++tail]=a[i];if (dcmp (Cross (Q[TAIL-1].V, Q[TAIL].V)) ==0) {-- Tail;if (OnL (A[I].P, Q[tail])) q[tail]=a[i];} if (front!=tail) B[tail-1]=lli (Q[tail], q[tail-1]);} while (Front!=tail &&!onl (B[tail-1], Q[front])--tail;if (tail-front<=1) return 0;cnt=0;b[tail]=lli (q[ Tail], Q[front]); For1 (i, Front, tail) S[++cnt]=b[i];return 1;} IL Line[n];ip a[n], B[n];int Ln, N, num, flag;void Add (IP A, IP b) {++ln; Line[ln].set (A, b);} void CLR () {num=ln=0;} void Readin () {read (n); For1 (i, 1, N) scanf ("%lf%lf", &a[i].x, &AMP;A[I].Y);} void Build () {A[n+1]=a[1];for1 (i, 1, N) Add (a[i+1], a[i]);} void work () {Flag=half (line, LN, b, num);} void Getans () {if (!flag) {puts ("0.00");} Double Ans=0;b[num+1]=b[1];for1 (i, 1, num) ans+=b[i].x*b[i+1].y-b[i].y*b[i+1].x;printf ("%.2f\n", ANS/2);} int main () {int ta=getint (), while (ta--) {clr (), Readin (); build (); work (); Getans ();} return 0;}

  

Bare half-plane sex ....... .....

"POJ" 1279

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.