Bzoj_1020_[shoi2008]_ Safe Route flight_ (compute geometry + dichotomy)

Source: Internet
Author: User
Tags polyline

Describe

http://www.lydsy.com/JudgeOnline/problem.php?id=1020

A route (polyline) is given to give a (c\) land (polygon). Find the farthest distance from the nearest land on the route.

Analysis

Also a question of God ...

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= -+5, maxm= -+5, maxq=1e6;5 Const Doubleeps=1e-8;6 intC,n;7 Doubleans;8InlineintDCMP (Doublex) {if(Fabs (x) <eps)return 0;Else returnX>0?1:-1; }9 structpt{Ten     Doublex, y; OneOtwDoublex=0,Doubley=0): X (x), Y (y) {} APtoperator+ (ConstPT &a)Const{returnPT (x+a.x,y+a.y); } -Ptoperator- (ConstPT &a)Const{returnPT (x-a.x,y-a.y); } -Ptoperator* (Const Double&AMP;P)Const{returnPT (x*p,y*p); } thePtoperator/ (Const Double&AMP;P)Const{returnPT (x/p,y/p); } -PT Normal () {returnPT (-y,x); } -     BOOL operator== (ConstPT &a)Const{return!DCMP (x-a.x) &&!dcmp (ya.y); } -     voidRead () {scanf ("%LF%LF",&x,&y); } + }A[MAXN]; - typedef PT VT; +InlineDoubleDOT (vt A,vt b) {returna.x*b.x+a.y*b.y;} AInlineDoubleCRS (VT A,vt b) {returna.x*b.y-a.y*b.x;} atInlineDoubleLen (vt a) {returnsqrt (dot (a,a));} - structsg{ - pt A, B; - sg () {} - sg (PT a,pt B): A (a), B (b) {} -     BOOLOnConstPT &p) {return!DCMP (CRS (A-P,B-P)) &&dcmp (dot (a-p,b-p)) <0; } in }Q[MAXQ]; - structpolygon{ to     intcnt; pt P[MAXM]; +     BOOL inch(ConstPT &a) { -         intwn=0; the          for(intI=1; i<=cnt;i++){ *             if(SG (p[i],p[i%cnt+1]). On (a))return true; $             intK=DCMP (CRS (p[i%cnt+1]-p[i],a-p[i]));Panax Notoginseng             intD1=DCMP (p[i].y-a.y); -             intD2=DCMP (p[i%cnt+1].y-a.y); the             if(k>0&&d1<=0&&d2>0) wn++; +             if(k<0&&d2<=0&&d1>0) wn--; A         } the         returnWN; +     } - }LAND[MAXN]; $ structnode{ $PT P;DoubleD; - node () {} -Node (PT p,Doubled):p (p), D (d) {} the }; - Inline PT Get_l_int (PT P,VT v,pt q,vt W) {WuyiVT u=p-Q; the     DoubleT=crs (w,u)/CRS (V,W); -     returnp+v*T; Wu } - Inline Node Dis_to_sg (pt p,pt a,pt b) { AboutVT v1=b-a,v2=p-a,v3=p-b; $     if(dcmp dot (v1,v2) <0))returnnode (A,len (v2)); -     Else if(dcmp dot (v1,v3) >0))returnnode (B,len (v3)); -     Else returnNode (Get_l_int (P,v1.normal (), A,V1), Fabs (CRS (V1,V2)/Len (v1 )); - } A Inline node Find (pt a) { +Node T; T.d=1<< -; the      for(intI=1; i<=c;i++){ -         if(Land[i].inch(a))returnNode (A,0); $          for(intj=1; j<=land[i].cnt;j++){ theNode Tmp=dis_to_sg (a,land[i].p[j],land[i].p[j%land[i].cnt+1]); the             if(DCMP (TMP.D-T.D) <0) t=tmp; the         } the     } -ans=Max (ANS,T.D); in     returnT; the } theInlinevoidinit () { Aboutscanf"%d%d",&c,&n); the      for(intI=1; i<=n;i++) A[i].read (); the      for(intI=1; i<=c;i++){ thescanf"%d",&land[i].cnt); +          for(intj=1; j<=land[i].cnt;j++) Land[i].p[j].read (); -     } the }BayiInlinevoidsolve () { the     intL=0, r=0; the      for(intI=1; i<n;i++) Q[R++]=SG (a[i],a[i+1]); -      while(l!=s) { -SG t=q[l++];if(L==MAXQ) L=0; thePT P1=find (T.A). P, P2=find (t.b). p,l=t.a,r=t.b,mid= (L+R)/2; the          while(Len (l-r) >1e-4){ theMid= (L+R)/2; the             if(Len (MID-P1) <len (MID-P2)) l=mid; -             ElseR=mid; the         } the         DoubleTmp=min (Len (MID-P1), Len (mid-p2)); the         if(ans+0.0001<tmp) {94Q[R++]=SG (T.a,mid);if(L==MAXQ) L=0;  theQ[R++]=SG (mid,t.b);if(L==MAXQ) L=0; the         } the     }98printf"%.2lf\n", ans); About } - intMain () {101 init ();102 solve ();103     return 0;104}
View Code

1020: [SHOI2008] Safe route flight time limit:1 Sec Memory limit:162 MB
submit:1021 solved:346
[Submit] [Status] [Discuss] Description

Safety is a very important issue when designing routes. First and foremost, all measures should be taken to ensure that no accidents occur in flight.
, but at the same time need to prepare for the worst, once the accident occurs, it is necessary to ensure that passengers have the highest possible chance of survival. When the plane landed on the sea,
The recent land is a key factor. The most dangerous part of the route is the farthest from the nearest land, which we call the route.
"Solitary location". The distance from the solitary location to the nearest land is known as the "lone distance". As a senior advisor to the airline, the first task you receive is
Try to find the solitary location of a route and calculate the solitary distance of the route. To simplify the problem, we think that the map is a two-dimensional plane where land can
To use a polygon approximation, the flight line is a polyline. The starting and ending points of the route are on land, but the intermediate turning point is probably at sea (as
indicated that the square marked the solitary location).

Input

The first line of input consists of two integers, C and N (1≤C≤20,2≤N≤20), representing the number of turning points of the number of land routes, respectively. Pick up the
To have n rows, each line has two integers, x, Y. (x, y) represents the coordinates of a route turning point, the first turning point is the beginning of the course, and the last turning point
To the end of the route. The next input will be used to describe the Block C continent. Each input is started by a positive integer m (m≤30), and M represents the vertex of a polygon
Number, the next m line, each row contains two integers x, y, (x, y) represents a vertex coordinate of the polygon, we guarantee that these vertices are clockwise or inverse
The hour hand shows the closure of the polygon without the occurrence of some side intersections. In addition, we guarantee that no two continents in the input data will intersect. Lose
All coordinates will be guaranteed to be between 10000 and 10000 of the range.

Output

Outputs a floating-point number that represents the solitary distance of the route, and the data retains 2 decimal places.

Sample Input1 2
-9-6
5 1
3
0 16
-16-12
17-6Sample Output0.00Hintsource

NWERC 2007

Bzoj_1020_[shoi2008]_ Safe Route flight_ (compute geometry + dichotomy)

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.