POJ 2540 Hotter Colder

Source: Internet
Author: User

http://poj.org/problem?id=2540

Test instructions: give you the path of each walk, and tell you each time away from a point light source is far or near, requiring each light source may exist in the area of the location.

Idea: If the "Same", indicating the light source on the perpendicular bisector, the area is 0, otherwise we consider far or near, in fact, in the path of two points connected to a straight line of the perpendicular bisector is a half-plane line, near the far side of the line, far away in the line near the side.

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 Const DoublePi=acos (-1);7 BOOLflag=0;8 inttot;9 structpoint{Ten     Doublex, y; One Point () {} APoint (DoubleX0,Doubley0): X (x0), Y (y0) {} -}a[200005],p[200005]; - structline{ the Point s,e; -     Doubleslop; - Line () {} - Line (Point S0,point E0): S (s0), E (E0) {} +}l[200005],l[200005],c[200005]; - intRead () { +     intt=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} at      while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} -     returnt*F; - } - Double operator*(Point p1,point p2) { -     returnp1.x*p2.y-p1.y*p2.x; - } inPointoperator+(Point p1,point p2) { -     returnPoint (p1.x+p2.x,p1.y+p2.y); to } +Pointoperator-(Point p1,point p2) { -     returnPoint (p1.x-p2.x,p1.y-p2.y); the } *Pointoperator/(Point P1,Doublex) { $     returnPoint (p1.x/x,p1.y/x);Panax Notoginseng } - BOOLCMP (line p1,line p2) { the     if(P1.slop!=p2.slop)returnp1.slop<P2.slop; +     Else return(P1.E-P1.S) * (P2.E-P1.S) <=0; A } thePoint Turn (Point P1,Doubleang) { +     DoubleCos=cos (ANG), sin=sin (ang); -     Doublex=p1.x*cos-p1.y*Sin; $     Doubley=p1.x*sin+p1.y*Cos; $     returnPoint (x, y); - } - Point Inter (line p1,line p2) { the     Doublet1= (P2.E-P1.S) * (p1.e-p1.s); -     DoubleT2= (P1.E-P1.S) * (p2.s-p1.s);Wuyi     Doublek= (T2)/(t1+T2); the     Doublex= (p2.e.x-p2.s.x) *k+p2.s.x; -     DoubleY= (P2.E.Y-P2.S.Y) *k+P2.s.y; Wu     returnPoint (x, y); - } About BOOLJud (line p1,line p2,line p3) { $Point p=Inter (P1,P2); -     return(P-P3.S) * (P3.E-P3.S) >0; - } - Doublequery () { AStd::sort (L +1, L +1+tot,cmp); +     if(!CMP (l[tot-1],l[tot]))return 0.0; the     intCnt=1; l[1]=l[1]; -      for(intI=2; i<=tot;i++) $      if(l[i].slop!=l[i-1].slop) l[++cnt]=L[i]; the     intLl=1, rr=2; c[ll]=l[1];c[rr]=l[2]; the      for(intI=3; i<=cnt;i++){ the          while(Ll<rr&&jud (c[rr],c[rr-1],l[i]) rr--; the          while(Ll<rr&&jud (c[ll],c[ll+1],l[i]) ll++; -c[++rr]=L[i]; in     }  the      while(Ll<rr&&jud (c[rr],c[rr-1],C[LL]) rr--; the      while(Ll<rr&&jud (c[ll],c[ll+1],C[RR]) ll++;  About     if(rr-ll+1<3) {flag=1;return 0.00;} the     Doubleans=0; theCnt=0; thec[rr+1]=C[ll]; +      for(inti=ll;i<=rr;i++) -A[++cnt]=inter (c[i],c[i+1]); thea[cnt+1]=a[1];Bayi      for(intI=1; i<=cnt;i++) theans+=a[i]*a[i+1];  theAns/=2.0; -     returnfabs (ans); - } the intMain () { thep[0]=point (0,0); the     Chars[200005];Doublex,y;flag=0;intI=1; theL[++tot].s=point (0,Ten); L[tot].e=point (0,0); L[tot].slop=atan2 (l[tot].e.y-l[tot].s.y,l[tot].e.x-l[tot].s.x); -L[++tot].s=point (0,0); L[tot].e=point (Ten,0); L[tot].slop=atan2 (l[tot].e.y-l[tot].s.y,l[tot].e.x-l[tot].s.x); theL[++tot].s=point (Ten,0); L[tot].e=point (Ten,Ten); L[tot].slop=atan2 (l[tot].e.y-l[tot].s.y,l[tot].e.x-l[tot].s.x); theL[++tot].s=point (Ten,Ten); L[tot].e=point (0,Ten); L[tot].slop=atan2 (l[tot].e.y-l[tot].s.y,l[tot].e.x-l[tot].s.x); the      while(SCANF ("%LF%LF", &p[i].x,&p[i].y)! =EOF) {94scanf"%s", s+1); the         if(s[1]=='S') flag=1; the         if(flag) {Puts ("0.00");Continue;}  the         if(s[1]=='C'){98Point Mid= (p[i]+p[i-1])/2.0; AboutL[++tot].e=mid+turn (p[i]-p[i-1],pi/2.0); -l[tot].s=mid;101}Else{102Point Mid= (p[i]+p[i-1])/2.0;103L[++tot].e=mid+turn (p[i]-p[i-1],pi*3.0/2.0);104l[tot].s=mid; the         }106L[tot].slop=atan2 (l[tot].e.y-l[tot].s.y,l[tot].e.x-l[tot].s.x);107printf"%.2f\n", query ());108i++;109     } the}

POJ 2540 Hotter Colder

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.