Graph theory, the determination of points in the interior of polygons.
1 /*1756*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> +#include <iterator> -#include <iomanip> + using namespacestd; A //#pragma COMMENT (linker, "/stack:102400000,1024000") at - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> - #definePII pair<int,int> in #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) to #definePer (i, a, n) for (int i=n-1;i>=a;--i) + #defineCLR Clear - #definePB Push_back the #defineMP Make_pair * #defineFIR First $ #defineSEC SecondPanax Notoginseng #defineAll (x) (x). Begin (), (x). End () - #defineSZ (x) ((int) (x). Size ()) the #defineLson L, Mid, rt<<1 + #defineRson mid+1, R, rt<<1|1 A the Const DoubleEPS = 1e-Ten; + Const intMAXN = the; - $ intDCMP (Doublex) { $ if(Fabs (x) < EPS)return 0; - returnx<0? -1:1; - } the -typedefstructPoint {Wuyi Doublex, y; the - Point () {} Wu -Point (DoubleX_Doubley_): About x (x_), Y (y_) {} $ } point; - - Point POLY[MAXN]; - intN; A +Pointoperator-(Point A, point B) { the returnPoint (a.x-b.x, a.y-b.y); - } $ the DoubleDot A, point B) { the returna.x*b.x + a.y*b.y; the } the - DoubleCross (Point A, point B) { in returna.x*b.y-a.y*b.x; the } the About BOOLonsegment (Point P, point A, point B) { the returnDCMP (Cross (a-p, b-p)) = =0&& dcmp (Dot (A-p, b-p)) <=0; the } the + BOOLIspointinpolygon (point P, point *Poly) { - intWN =0; the BayiRep (I,0, N) { the if(Onsegment (P, Poly[i], poly[(i+1)%n])) the return true; - intK = dcmp (Cross (poly[(i+1)%n]-poly[i], ppoly[i])); - intD1 = dcmp (Poly[i].y-p.y); the intD2 = dcmp (poly[(i+1)%n].y-p.y); the the if(k>0&& d1<=0&& d2>0) ++WN; the if(k<0&& d2<=0&& d1>0) --WN; - } the the returnwn!=0; the }94 the intMain () { theIos::sync_with_stdio (false); the #ifndef Online_judge98Freopen ("data.in","R", stdin); AboutFreopen ("Data.out","W", stdout); - #endif101 102 intm;103 BOOLFlag;104 Point p; the 106 while(SCANF ("%d", &n)! =EOF) {107Rep (I,0, N)108scanf"%LF%LF", &poly[i].x, &poly[i].y);109scanf"%d", &m); the while(m--) {111scanf"%LF%LF", &p.x, &p.y); theFlag =Ispointinpolygon (P, poly);113Puts (flag?)"Yes":"No"); the } the } the 117 #ifndef Online_judge118printf"Time =%d.\n", (int) clock ());119 #endif - 121 return 0;122}
"Hdoj" 1756 Cupid ' s Arrow