Sicily 2016. Emergent escape, sicilyemergent
Question
Ideas
Suddenly I found this code in the trumpet, and I didn't do it in the big one.
I forgot my mind. This code should be written by someone else.
The annotations are quite clear.
Code
# Include <stdio. h> # include <math. h> # include <string. h> const int maxn = 1000 + 10; // maximum meteorite count const double eps = 1e-8; // control precision const double pi = acos (-1.0 ); // circumference rate double d1, d2, R; // The radians of the start and end points, and the coordinates of the radius double xd1, yd1, xd2, and yd2 of the spacecraft. // The coordinates of the start and end points. Int n; // double x [maxn], y [maxn], r [maxn]; // The coordinate and radius of the meteorite center int a [maxn] [maxn]; // undirected graph int B [maxn]; // The inline double dis (double x, double y) {// returns sqrt (x * x + y * y);} inline double helen (double a, double B, double c) {double p = (a + B + c)/2.0; // return sqrt (p * (p-a) of the triangle area where the length of the formula is a, B, and c) * (p-B) * (p-c);} int intersect (int I, int j) {// use the area to determine whether the intersection of the I and j circles is in the spacecraft. // Side length double di = dis (x [I], y [I]); double dj = dis (x [j], y [j]); double ij = dis (x [I]-x [j], y [I]-y [j]); // calculate the area of the four triangles. double S = helen (di, dj, ij); double Si = helen (di, r [I], R ); double Sj = helen (dj, r [j], R); double Sij = helen (ij, r [I], r [j]); // use the area of the four triangles to determine return Si + Sj + Sij> S;} int dfs (int root) {// depth-first traversal if (B [root] = 2) return 0; // if a node marked as 2 is found, B [root] = 0 is returned; // mark int I; for (I = 0; I <n; I ++) if (B [I] & a [root] [I] = cas) {if (dfs (I) = 0) return 0; // if no access is made, visit} return 1;} int main () {// Number of read data groups int T; scanf ("% d ", & T); double tmp, d, di; // Temporary Variable int OK; // feasible marker int I, j; // cyclic variable memset (a, 0, sizeof (a); // set cas to 0 for a; // data sequence number while (T --) {cas ++; scanf ("% lf ", & R, & d1, & d2); // read radius // exchange to ensure d1 <= d2 if (d1> d2) {tmp = d1; d1 = d2; d2 = tmp;} // converts degrees to radians d1 = pi/180.0 * D1; d2 = pi/180.0 * d2; // start and end coordinates xd1 = R * cos (d1); yd1 = R * sin (d1 ); xd2 = R * cos (d2); yd2 = R * sin (d2); // read the meteorite coordinate scanf ("% d", & n); for (I = 0; I <n; I ++) scanf ("% lf", & x [I], & y [I], & r [I]); OK = 1; memset (B, 0, sizeof (B); // clear the B array for (I = 0; I <n; I ++) {// traverse the meteorite d = dis (x [I], y [I]); // calculate the distance from if (d> R + r [I] + eps) {// phase separation, marked as 0 B [I] = 0; continue;} if (r [I] + d + eps <R) {// phase included, mark as 3 B [I] = 3; continue;} // The meteorite directly hits the starting point or end point if (dis (x [I]-xd1, y [I]-yd1) <= eps + r [I] | dis (x [I]-xd2, y [I]-yd2) <= eps + r [I]) {OK = 0; // no solution continue;} // calculates the radian di = acos (x [I]/d) of the center. if (y [I] <0.0) di = pi + pi-di; // determine the intersection interval if (di> d1 & di <d2) B [I] = 1; else B [I] = 2;} if (! OK) {// If the meteorite hits the starting point or the ending point printf ("Die hard! \ N "); continue;} // otherwise, traverse for (I = 0; I <n; I ++) if (B [I]) for (j = I + 1; j <n; j ++) if (B [j]) if (dis (x [I]-x [j], y [I]-y [j]) <= r [I] + r [j]) {if (B [I] + B [j]! = 3 | intersect (I, j) // if the two meteorite intersect, the edge a [I] [j] = a [j] [I] = cas ;} // start traversing each vertex marked as 1 to see if it can reach the vertex marked as 2 (I = 0; I <n; I ++) {if (B [I] = 1) OK = dfs (I); if (! OK) break;} // output determination result if (OK) printf ("Escape! \ N "); else printf (" Die hard! \ N ") ;}return 0 ;}