UVa P393 rokua P1354 vijos P1013 Room Shortest circuit problem calculation geometry judging segment intersection shortest

Source: Internet
Author: User

Title Index: https://www.luogu.org/problemnew/show/P1354

Title Description

In a long and wide 10, the entrance exit is (0,5), (10,5) of the room, there are several walls, each wall has two notches, for the entrance to the shortest route to the exit.

input/output format Input Format:

The first row is N (n<=20), the number of walls.

Next n rows, each row of 5 real x,a1,b1,a2,b2.

x indicates the horizontal axis of the wall (all walls are vertical), and the A1-B1 and A2-B2 are vacant.

A1, B1, A2, B2 keep increasing, and x1-xn is also increasing. output Format:

Outputs the shortest distance and retains 2 decimal places. input/Output sample Input Sample # #: copy

2
4 2 7 8 9
7 3 4.5 6 7
Sample # # of output:Copy
10.06


Topic Analysis (no direct solution of good analysis):

Take the starting point and the top and bottom two points of each door as a point in the picture, then enumerate two points, and use the cross product to determine whether two points intersect the wall, if not intersect an edge. Then run a trip from the starting point to the end Dijkstra (attention to detail).

      The AC on the valley, the data on the Vijos is not over ... UVA has not been handed in locally. Attach the reference code first:

#include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream > #include <algorithm> #define DB double #define SG string #define LL Long Long #define FP (a,b,c,d) for (a=b; a<=c; A+=d) #define FM (a,b,c,d) for (a=b; a>=c;
A-=d) #define CLEAR (a) memset (A,0,sizeof (a)) using namespace Std;
Const LL max=1e4+5;
Const LL MOD=1E9+7;
Const LL INF=1E10;
Const DB eps=1e-8;
LL N,p,q,cnt,vis[max];D b Dis[max];
LL To[max<<1],next[max<<1],head[max];D b edge[max<<1];
	struct node{LL Num;
	DB Dis;
	BOOL operator < (const Node &a) const{return a.dis<dis;
}
}; struct point{DB x, y;}
_POINT[105];
	struct line{point Start;
Point End;
}ROOM[105];
	inline int Read () {bool F=0;int X=0;char Ch=getchar (); while (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') f=1;
	Ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x= (x<<3) + (x<<1) +ch-' 0 ';
	Ch=getchar ();}
return f?-x:x; } inline void Write (int X) {if (x<0) X=-x,putchAR ('-');
	if (x>9) Write (X/10);
Putchar (x%10+48);
	} LL Cmp (DB D) {if (Fabs (d) <eps) {return 0;
}return (d>0) 1:-1;
} DB Det (db x1,db y1,db x2,db Y2) {return x1*y2-x2*y1;} DB Cross (Point x,point y,point Z) {return Det (y.x-x. X,y.y-x. Y,z.x-x. X,z.y-x.
Y); } bool Check (line N,line M) {return (CMP (n.start,m.start,m.end) ^cmp (Cross (n.end,m.start,m.end))) ==-2 &&amp
;(Cmp (Cross (m.start,n.start,n.end)) ^cmp (Cross (m.end,n.start,n.end))) ==-2; } void Insert (LL x,ll y,db Z) {to[++cnt]=y; Edge[cnt]=z; NEXT[CNT]=HEAD[X];
head[x]=cnt;
	} void Dijkstra_heap (ll S) {ll i,j,k;
	priority_queue<node>q;
	Fp (i,1,p,1) {dis[i]=inf*1.0; }dis[s]=0.0; Node Tmp; Tmp.num=s;
	Q.push (TMP); while (Q.size ()) {LL x=q.top (). Num;
		Q.pop ();
			if (vis[x]==false) {vis[x]=true;
				for (I=head[x];i;i=next[i]) {LL y=to[i];
				DB Z=edge[i]; if (!
					vis[y]&&dis[y]>dis[x]+z) {dis[y]=dis[x]+z;
					Tmp.num=y;
					Tmp.dis=dis[y];
				Q.push (TMP); }}}}} int main () {LL I,J,k;
	N=read ();
		Fp (i,1,n,1) {DB x;scanf ("%lf", &x);
			Fp (j,1,4,1) {DB y;scanf ("%lf", &y); _POINT[++P].
			X=x; _POINT[P].
		Y=y; } Room[++q].
		Start.x=x; ROOM[Q].
		start.y=0; ROOM[Q].
		End.x=x; ROOM[Q]. End.y=_point[p-3].
		Y ROOM[++Q].
		Start.x=x; ROOM[Q]. Start.y=_point[p-2].
		Y ROOM[Q].
		End.x=x; ROOM[Q]. END.Y=_POINT[P-1].
		Y ROOM[++Q].
		Start.x=x; ROOM[Q]. START.Y=_POINT[P].
		Y ROOM[Q].
		End.x=x; ROOM[Q].
	end.y=10*1.0; } _point[++p]. X=10.0;_POINT[P].
	y=5.0; _POINT[++P]. X=0.0;_POINT[P].
	y=5.0;
			FP (i,1,p-2,1) {fp (J, (i/4+1) *4+1,p-1,1) {line L;bool mark=0;
			L.start=_point[i];
			L.END=_POINT[J];
					Fp (k,1,q,1) {if (Check (L,room[k]) ==true) {mark=1;
				Break }} if (mark==0) {Insert (I,j,sqrt ((l.start.x-l.end.x) * (l.start.x-l.end.x) + (L.START.Y-L.END.Y) * (L.START.Y-L.END.Y)
			));
		}}} Fp (i,1,p-1,1) {line L;bool mark=0;
		L.START=_POINT[P];
		L.end=_point[i];
				Fp (j,1,q,1) {if (Check (L,room[j]) ==true) {mark=1;
			Break }} if(mark==0)
		{Insert (P,I,SQRT (l.start.x-l.end.x) * (l.start.x-l.end.x) + (L.START.Y-L.END.Y) * (L.START.Y-L.END.Y));
	}} dijkstra_heap (P);
	printf ("%.2lf", dis[p-1]);
return 0; }

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.