The Doors
Time Limit:1000 MS |
|
Memory Limit:10000 K |
Total Submissions:5258 |
|
Accepted:2140 |
Description
You are to find the length of the shortest path through a chamber containing obstructing Wils. the chamber will always have sides at x = 0, x = 10, y = 0, and y = 10. the initial and final points of the path are always (0, 5) and (10, 5 ). there will also be
From 0 to 18 vertical wallinside the chamber, each with two doorways. The figure below tables strates such a chamber and also shows the path of minimal length.
Input
The input data for the specified strated chamber wowould appear as follows.
2
4 2 7 8 9
7 3 4.5 6 7
The first line contains the number of interior Wils. then there is a line for each such wall, containing five real numbers. the first number is the x coordinate of the wall (0 <x <10), and the remaining four are the y coordinates of the ends of the doorways
In that wall. the x coordinates of the wallare in increasing order, and within each line the y coordinates are in increasing order. the input file will contain in at least one such set of data. the end of the data comes when the number of Wils is-1.
Output
The output shoshould contain one line of output for each chamber. the line shoshould contain the minimal path length rounded to two decimal places past the decimal point, and always showing the two decimal places past the decimal point. the line shoshould contain no
Blanks.
Sample Input
15 4 6 7 824 2 7 8 97 3 4.5 6 7-1
Sample Output
10.0010.06
This is a question about the combination of computational ry and the most short circuit. The key to the question is how to create a graph. I have no idea about computational ry. I only know a little about it after I have watched the big post. The following code is used:
# Include <iostream> # include <cmath> # include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # define eps 1e-8 # define inf 100000000 using namespace std; struct Wall {double x; double y [6];} wall [20]; double dist [80] [80]; double xmult (double x0, double y0, double x1, double y1, double x2, double y2) {return (x1-x0) * (y2-y0)-(x2-x0) * (y1-y0);} int dblcmp (double) {if (fabs (a) <eps) return 0; ret Urn (a> 0 )? 1:-1;} bool Cross (double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3) {// determine whether two straight lines intersect. return (dblcmp (xmult (x0, y0, x2, y2, x3, y3) ^ dblcmp (xmult (x1, y1, x2, y2, x3, y3) =-2 & (dblcmp (xmult (x2, y2, x0, y0, x1, y1) ^ dblcmp (xmult (x3, y3, x0, y0, x1, y1) =-2;} bool Direct (int I, int j, int p, int q) {// determine whether to go from the j of the wall I to the q of the p to int k, l; for (k = I + 1; k <p; k ++) {for (l = 0; l <6; l + = 2) If (Cross (wall [I]. x, wall [I]. y [j], wall [p]. x, wall [p]. y [q], wall [k]. x, wall [k]. y [l], wall [k]. x, wall [k]. y [l + 1]) return false;} return true;} inline double Dist (double x1, double y1, double x2, double y2) {return sqrt (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2);}; typedef double elem_t; double dijkstra (int n) {int v [81], I, j, k; double min [81]; for (I = 0; I <= n; I ++) min [I] = inf, v [I] = 0; for (min [0] = 0, j = 0; j <= n; j ++) {fo R (k =-1, I = 0; I <= n; I ++) if (! V [I] & (k =-1 | min [I] <min [k]) k = I; for (v [k] = 1, I = 0; I <= n; I ++) if (! V [I] & min [k] + dist [k] [I] <min [I]) min [I] = min [k] + dist [k] [I];} return min [n];} int main () {int n, I, j, k, l; wall [0]. x = 0; wall [0]. y [0] = 5; while (scanf ("% d", & n) & n! =-1) {for (I = 0; I <= n * 4 + 1; I ++) for (j = 0; j <= n * 4 + 1; j ++) dist [I] [j] = inf; wall [n + 1]. x = 10; wall [n + 1]. y [1] = 5; bool con = true; for (I = 1; I <= n; I ++) {scanf ("% lf ", & wall [I]. x); for (j = 1; j <5; j ++) scanf ("% lf", & wall [I]. y [j]); if (wall [I]. y [1]> 5 | wall [I]. y [4] <5 | wall [I]. y [2] <5 & wall [I]. y [3]> 5) con = false; wall [I]. y [0] = 0; wall [I]. y [5] = 10;} if (con) {puts ("10.00"); continue;} for (I = 1; I <= n; I ++) {for (j = 1; j <5; j ++) {if (I <n) for (k = 1; k <5; k ++) dist [I * 4 + j-4] [I * 4 + k] = Dist (wall [I]. x, wall [I]. y [j], wall [I + 1]. x, wall [I + 1]. y [k]); if (Direct (0, 0, I, j) dist [0] [I * 4 + j-4] = Dist (, wall [I]. x, wall [I]. y [j]); if (Direct (I, j, n + 1, 1 )) dist [I * 4 + j-4] [n * 4 + 1] = Dist (wall [I]. x, wall [I]. y [j], 10, 5); for (k = I + 2; k <= n; k ++) for (l = 1; l <5; l ++) if (Direct (I, j, k, l) dist [I * 4 + j-4] [k * 4 + L-4] = Dist (wall [I]. x, wall [I]. y [j], wall [k]. x, wall [k]. y [l]) ;}} printf ("%. 2lf \ n ", dijkstra (n * 4 + 1);} return 0 ;}