The Doors shortest circuit + simple geometry

Source: Internet
Author: User

The Doors

Abstract: Give you some points, and some obstacles to the edge of the line. Ask the shortest geometric distance from the origin to the end point.

Analysis: After the pretreatment see diagram, run the shortest way.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 using namespacestd;6 Const intINF =0x5fffffff;7 Const intMS =1005;8 Const intMS2 = -;9 Ten structPoint { One     Doublex, y; A    //Point (Double _x = 0, double _y = 0): X (_x), Y (_y) {} -     //the OJ of the compiler is not updated for a long time and may not support pioint{} initialization. You can change to constructor point () initialization.  - }points[ms]; the structEdge { -     intu, v; -     DoubleW; -}edges[ms *MS]; +  - intpSize, esize; + intN; A  at DoubleW[MS], wy[ms][4]; - DoubleDis[ms]; -  - DoubleDConstPoint &a,ConstPoint &b) { -     returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-b.y)); - } in  - DoubleCConstPoint &a,ConstPoint &b,ConstPoint &c) { to     return(C.Y-A.Y) * (a.x-b.x)-(A.Y-B.Y) * (c.x-a.x); + } -  the BOOLIsOk (ConstPoint &a,ConstPoint &b) { *     if(A.x >=b.x) $         return false;Panax Notoginseng     inti =0; -      while(I < n && W[i] <=a.x) thei++; +      while(I < n && W[i] <b.x) { A         if(C (A, B, Point{w[i],0}) * C (A, B, point{w[i],wy[i][0]}) <0) the             return false; +         if(C (A, B, point{w[i],wy[i][1]}) * C (A, B, point{w[i], wy[i][2]}) <0) -             return false; $         if(C (A, B, point{w[i], wy[i][3]}) * C (A, B, Point{w[i],10.0}) <0) $             return false; -i++; -     } the     return true; - }Wuyi  the intinput () { -scanf"%d", &n); Wu     if(n = =-1) -         return 0; AboutPSize =0; $points[psize].x =0; -POINTS[PSIZE++].Y =5; -      for(inti =0; I < n; i++) { -scanf"%LF", &w[i]); A          for(intj =0; J <4; j + +) { +points[psize].x =W[i]; thescanf"%LF", &wy[i][j]); -POINTS[PSIZE++].Y =Wy[i][j]; $         } the     } thepoints[psize].x =Ten; thePOINTS[PSIZE++].Y =5; the  -Esize =0; in      for(inti =0; i < pSize; i++) { the          for(intj = i +1; J < PSize; J + +) { the             if(IsOk (Points[i], points[j])) { AboutEDGES[ESIZE].U =i; theEDGES[ESIZE].V =J; theEDGES[ESIZE++].W =D (Points[i], points[j]); the             } +         } -     } the     return 1;Bayi } the  the voidBellman (intv0) { -      for(inti =0; i < pSize; i++) -Dis[i] = INF;//Fill (Dis,dis + pSize, INF) theDis[v0] =0.0; the     intFlag =1; the      for(intt =1; T < pSize && flag; t++) { theFlag =0; -          for(inti =0; i < esize; i++) { the             if(DIS[EDGES[I].U] + EDGES[I].W <DIS[EDGES[I].V]) { theDIS[EDGES[I].V] = dis[edges[i].u] +EDGES[I].W; theFlag =1;94             } the         } the     } the }98  About intMain () { -      while(Input ()) {101Bellman (0);102printf"%.2lf\n", Dis[psize-1]);103     }104     return 0; the}

The Doors shortest circuit + simple geometry

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.