bzoj1137 "POI2009" Wsp Island

Source: Internet
Author: User

1137: [Poi2009]wsp Island Time limit: Sec Memory Limit: 162 mbsec Special Judge
Submit: Solved: 38
[Submit] [Status] [Discuss] Description

The Byteotia island is a convex polygon. The city is all on the coast. Number 1 to n clockwise. There is a straight road connecting any of the two cities. The intersection of the road is freely accessible. Some of the roads were controlled by the guerrillas, unable to walk, but could pass the intersection of the road and the uncontrolled road. Ask for the shortest distance from City 1 to N.

Input

The first line of positive integer n m represents the number of cities and the number of islands controlled (3≤n≤10^5 1≤m≤10^6) the next n rows of two integers per line x y represent the coordinates of each city. (|x|,|y|≤10^6) The next M-line describes a path that cannot be walked (the start and end points). Data is guaranteed to be solvable.

Output

Output a real number, the shortest distance, the error 10^-5 is correct within.

Sample Input6 9
-12-10
-11 6
-4 12
6 14
16 6
18-2
3 4
1 5
2 6
2 3
4 5
3 5
1 3
3 6
1 6Sample Output42.000000000HINT

Source

Acknowledgement vfleaking




semi-planar cross ideas and good questions

Because the 1-n is arranged clockwise, the shortest path of the 1-n is the length of the half-plane intersection of all the segments that can be used.

However, this is not possible because the edge will have an O (n^2) bar.

Each point starting point, must be the better after the better, so as long as the preservation of the next, so that the edge is only O (n).




#include <iostream> #include <cstdlib> #include <cmath> #include <cstdio> #include <cstring > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long long#define MAXN 100005#define maxm 1000005#define eps 1e-8using namespace std;int n,m,cnt,tot;double ans;s Truct p{double x, y; P (double xx=0,double yy=0) {x=xx;y=yy;} Friend P operator-(p a,p b) {return P (A.X-B.X,A.Y-B.Y);} Friend double operator * (P a,p b) {return a.x*b.y-a.y*b.x;}} P[maxn],a[maxn];struct l{p a,b;double angle;friend bool operator < (L a,l b) {if (Fabs (a.angle-b.angle) <=eps) return (A.B-A.A) * (B.B-A.A) >0;else return a.angle<b.angle;}} L[maxn],q[maxn];struct Edge{int x,y;friend bool operator < (Edge A,edge b) {return a.x==b.x?a.y>b.y:a.x<b.x;}} E[maxm];inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} Return X*f;} inline double dis (P a,p b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} Inline P Inter (L l1,l L2) {double k1= (l2.b-l1.a) * (l1.b-l1.a), k2= (l1.b-l1.a) * (l2.a-l1.a), t=k1/(K1+K2); return P (l2.b.x+ (l2.a.x-l2.b.x) *t,l2.b.y+ (L2.A.Y-L2.B.Y) *t);} inline bool Judge (L l1,l l2,l t) {P p=inter (L1,L2); return (T.B-T.A) * (P-T.A) <-eps;} inline void HPi () {F (i,1,cnt) l[i].angle=atan2 (l[i].b.y-l[i].a.y,l[i].b.x-l[i].a.x); sort (l+1,l+cnt+1); int head=1, Tail=0;tot=1; F (i,2,cnt) {if (Fabs (l[i].angle-l[i-1].angle) >=eps) tot++;l[tot]=l[i];} CNT=TOT;Q[++TAIL]=L[1];Q[++TAIL]=L[2]; F (i,3,cnt) {while (Head<tail&&judge (Q[tail],q[tail-1],l[i])) Tail--;while (Head<tail&&judge ( Q[head],q[head+1],l[i]) head++;q[++tail]=l[i];} while (Head<tail&&judge (Q[tail],q[tail-1],q[head))) tail--;tot=0; F (I,HEAD,TAIL-1) a[++tot]=inter (q[i],q[i+1]); A[++tot]=inter (Q[head],q[tail]);} int main () {n=read (); M=read (); F (I,1,n) P[i].x=read (), P[i].y=read (); F (i,1,m) {e[i].x=read (); E[i].y=read (); if (E[i].x> e[i].y) swap (E[I].X,E[I].Y);} Sort (e+1,e+m+1); if (e[1].x!=1| | E[1].y!=n) {printf ("%.10lf\n", Dis (p[1],p[n])); return 0;} int t=1; F (i,1,n-1) {int j=n;while (t<=m&&e[t].x==i&&e[t].y==j&&j>i) J--, t++;if (j>i) l[++ Cnt]= (L) {p[j],p[i]};while (t<=m&&e[t].x==i) t++;} L[++cnt]= (L) {p[1],p[n]};hpi (); A[0]=a[tot]; F (I,1,tot) Ans+=dis (a[i],a[i-1]) Ans-=dis (P[1],p[n]);p rintf ("%.10lf\n", ans); return 0;}


bzoj1137 "POI2009" Wsp Island

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.