Time limit: 2000 ms |
|
Memory limit: 65536 K |
Total submissions: 708 |
|
Accepted: 291 |
Description
While
Creating a customer logo, ACM uses graphical utilities to draw
Picture that can later be cut into special fluorescent materials.
Ensure proper processing, the shapes in the picture cannot intersect.
However, some logos contain such intersecting shapes. It is necessary
Detect them and decide how to change the picture.
Given a set
Geometric shapes, you are to determine all of their intersections. Only
Outlines are considered, if a shape is completely inside another one, it
Is not counted as an intersection.
Input
Input
Contains several pictures. Each picture describes at most 26 shapes,
Each specified on a separate line. The line begins with an uppercase
Letter that uniquely identifies the shape inside the corresponding
Picture. Then there is a kind of the shape and two or more points,
Everything separated by at least one space. Possible shape kinds are:
• Square: followed by two distinct points giving the opposite corners of the square.
•
Rectangle: three points are given, there will always be a right angle
Between the Lines Connecting the first point with the second and
Second with the third.
• Line: Specifies a line segment, two distinct end points are given.
• Triangle: three points are given, they are guaranteed not to be co-linear.
•
Polygon: followed by an integer number N (3 ≤ n ≤ 20) and N points
Specifying vertices of the polygon in either clockwise or anti-clockwise
Order. The polygon will never intersect itself and its sides will have
Non-zero length.
All points are always given as two integer
Coordinates X and Y separated with a comma and enclosed in parentheses.
You may assume that | x |, | Y | ≤ 10000.
The picture description is
Terminated by a line containing a single dash ("-"). After the last
Picture, there is a line with one dot (".").
Output
For
Each picture, output one line for each of the shapes, sorted
Alphabetically by its identifier (X). The line must be one of
Following:
• "X has no intersections", if X does not intersect with any other shapes.
• "X intersects with a", if X intersects with exactly 1 other shape.
• "X intersects with A and B", if X intersects with exactly 2 other shapes.
• "X intersects with a, B,..., and Z", if X intersects with more than 2 other shapes.
Please
Note that there is an additional comma for more than two intersections.
A, B, etc. Are all intersecting shapes, sorted alphabetically.
Print one empty line after each picture, including the last one.
Sample Input
A square (1,2) (3,2)
F line (1,3) (4,4)
W triangle (3,5) (5,5) (4,3)
X triangle (7,2) (7,4) (5,3)
S polygon 6 (9,3) (10,3) (10,4) (8,4) (8,1) (10,2)
B rectangle (3,3) (7,5) (8,3)
-
B square (1,1) (2,2)
A square (3,3) (4,4)
-
.
Sample output
A has no intersections
B intersects with S, W, and X
F intersects with W
S intersects with B
W intersects with B and F
X intersects with B
A has no intersections
B has no intersections
Source
The input and output of CTU Open 2007 geometries are troublesome, but the question is relatively simple. # Include <stdio. h> <br/> # include <string. h> <br/> # include <math. h> <br/> # include <stdlib. h> <br/> const double EPS = 1e-6; <br/> const double Pi = 3.1415926; <br/> struct point <br/>{< br/> double X, y; <br/>}; <br/> struct segment <br/>{< br/> Point U, V; <br/> }; <br/> struct shape <br/> {<br/> char name, inters [30]; <br/> int num, internum; <br/> segment P [20]; <br/>} s [30]; <br/> int CMP (const void * a, const void * B) <br/> {<br/> return (* (shape *) ). name-(* (shape *) B ). name; <br/>}< br/> double min (double A, double B) <br/>{< br/> return a <B? A: B; <br/>}< br/> double max (double A, double B) <br/>{< br/> return A> B? A: B; <br/>}< br/> double dist (point a, point B) <br/>{< br/> return SQRT (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y); <br/>}< br/> double getangle (point a, point O) <br/>{< br/> return atan2 (. y-o.y,. x-o.x); <br/>}< br/> point getmidpoint (point a, point B) <br/>{< br/> point C; <br/> C. X = (. X + B. x) * 0.5; <br/> C. y = (. Y + B. y) * 0.5; <br/> return C; <br/>}< br/> void rotate (point a, point O, point & B, double GLE) <br/>{< br/> double an = getangle (A, O) + angle; <br/> double D = dist (A, O ); <br/> B. X = O. X + D * Cos (an); <br/> B. y = O. Y + D * sin (an); <br/>}< br/> double cross (point a, point B, point O) <br/>{< br/> return (. x-o.x) * (B. y-o.y)-(. y-o.y) * (B. x-o.x); <br/>}< br/> double dblcmp (double r) <br/>{< br/> If (FABS (r) <EPS) <br/>{< br/> return 0; <br/>}< br/> return r> 0? 1:-1; <br/>}< br/> void copypoint (point & A, point B) <br/>{< br/>. X = B. x,. y = B. y; <br/>}< br/> void inputpoint (point & P) <br/>{< br/> scanf ("(% lf, % lf )", & P. x, & P. y); <br/>}< br/> void inputsquare (char name, int N) <br/>{< br/> S [N]. name = Name; <br/> S [N]. num = 4; <br/> inputpoint (s [N]. P [0]. u); <br/> inputpoint (s [N]. P [2]. u); <br/> rotate (s [N]. P [0]. u, getmidpoint (s [N]. P [0]. u, S [N]. P [2]. u), s [N]. P [1]. u, pI * 0.5); <br/> rotate (s [N]. P [2]. u, getmidpoint (s [N]. P [0]. u, S [N]. P [2]. u), s [N]. P [3]. u, pI * 0.5); <br/> copypoint (s [N]. P [0]. v, s [N]. P [1]. u); <br/> copypoint (s [N]. P [1]. v, s [N]. P [2]. u); <br/> copypoint (s [N]. P [2]. v, s [N]. P [3]. u); <br/> copypoint (s [N]. P [3]. v, s [N]. P [0]. u); <br/>}< br/> void inputrectangle (char name, int N) <br/>{< br/> S [N]. name = Name; <br/> S [N]. num = 4; <br/> inputpoint (s [N]. P [0]. u); <br/> in Putpoint (s [N]. P [1]. u); <br/> inputpoint (s [N]. P [2]. u); <br/> rotate (s [N]. P [1]. u, getmidpoint (s [N]. P [0]. u, S [N]. P [2]. u), s [N]. P [3]. u, Pi); <br/> copypoint (s [N]. P [0]. v, s [N]. P [1]. u); <br/> copypoint (s [N]. P [1]. v, s [N]. P [2]. u); <br/> copypoint (s [N]. P [2]. v, s [N]. P [3]. u); <br/> copypoint (s [N]. P [3]. v, s [N]. P [0]. u); <br/>}< br/> void inputline (char name, int N) <br/>{< br/> S [N]. name = Name; <br/> S [N]. num = 1; <Br/> inputpoint (s [N]. P [0]. u); <br/> inputpoint (s [N]. P [0]. v); <br/>}< br/> void inputtriangle (char name, int N) <br/>{< br/> S [N]. name = Name; <br/> S [N]. num = 3; <br/> inputpoint (s [N]. P [0]. u); <br/> inputpoint (s [N]. P [1]. u); <br/> inputpoint (s [N]. P [2]. u); <br/> copypoint (s [N]. P [0]. v, s [N]. P [1]. u); <br/> copypoint (s [N]. P [1]. v, s [N]. P [2]. u); <br/> copypoint (s [N]. P [2]. v, s [N]. P [0]. u); <br/>}< br/> void Indium Utpolygon (char name, int N) <br/>{< br/> S [N]. name = Name; <br/> scanf ("% d", & S [N]. num); <br/> inputpoint (s [N]. P [0]. u); <br/> for (INT I = 1; I <s [N]. num; I ++) <br/>{< br/> inputpoint (s [N]. P [I]. u); <br/> copypoint (s [N]. P [I]. v, s [N]. [I-1]. u); <br/>}< br/> copypoint (s [N]. P [0]. v, s [N]. P [s [N]. num-1]. u); <br/>}< br/> bool quick (point a, point B, point C, point D) <br/>{< br/> return max (. x, B. x)> = min (C. x, D. x) And Max (. y, B. y)> = min (C. y, D. y) and max (C. x, D. x)> = min (. x, B. x) and max (C. y, D. y)> = min (. y, B. y); <br/>}< br/> bool intersegment (point a, point B, point C, point D) <br/>{< br/> If (quick (A, B, C, D) <br/>{< br/> int d1 = dblcmp (Cross (, c, D); <br/> int D2 = dblcmp (Cross (B, C, D); <br/> int D3 = dblcmp (Cross (C,, b); <br/> int D4 = dblcmp (Cross (D, a, B )); <br/> return D1 * D2 <= 0 and D3 * D4 <= 0; <br/>}< br/> bool Intershape (shape & A, shape & B) <br/>{< br/> for (INT I = 0; I <. num; I ++) <br/>{< br/> for (Int J = 0; j <B. num; j ++) <br/>{< br/> If (intersegment (. P [I]. u,. P [I]. v, B. P [J]. u, B. P [J]. v) <br/>{< br/> return true; <br/>}< br/> return false; <br/>}< br/> void checkinter (int n) <br/>{< br/> for (INT I = 0; I <n; I ++) <br/> {<br/> for (Int J = I + 1; j <n; j ++) <br/> {<br/> If (intershape (s [I], s [J]) <br />{< Br/> S [I]. inters [s [I]. internum ++] = s [J]. name; <br/> S [J]. inters [s [J]. internum ++] = s [I]. name; <br/>}< br/> int main () <br/>{< br/> int N; <br/> char name [30], shape [30]; <br/> while (true) <br/>{< br/> n = 0; <br/> while (scanf ("% s", name), * name! = '-' And * name! = '. ') <Br/>{< br/> scanf ("% s", shape); <br/> switch (* shape) <br/> {<br/> case's ': <br/> inputsquare (* Name, n); <br/> break; <br/> case 'r': <br/> inputrectangle (* Name, n); <br/> break; <br/> case 'l ': <br/> inputline (* Name, n); <br/> break; <br/> case 'T': <br/> inputtriangle (* Name, N ); <br/> break; <br/> case 'p': <br/> inputpolygon (* Name, n); <br/> break; <br/>}< br/> S [n ++]. internum = 0; <br/>}< br/> If (* name = '. ') break; <br/> qsort (S, N, sizeof (* s), CMP); <br/> checkinter (N ); <br/> for (INT I = 0; I <n; I ++) <br/> {<br/> switch (s [I]. internum) <br/>{< br/> case 0: <br/> printf ("% C has no intersections/N", s [I]. name); <br/> break; <br/> case 1: <br/> printf ("% C intersects with % C/N", s [I]. name, s [I]. inters [0]); <br/> break; <br/> case 2: <br/> printf ("% C intersects with % C and % C/N ", s [I]. name, s [I]. inters [0], s [I]. inters [1]); <br/> break; <br/> default: <br/> printf ("% C intersects with", s [I]. name); <br/> for (Int J = 0; j <s [I]. interNum-1; j ++) <br/>{< br/> printf ("% C,", s [I]. inters [J]); <br/>}< br/> printf ("and % C/N", s [I]. inters [s [I]. interNum-1]); <br/>}< br/> printf ("/N"); <br/>}< br/> return 0; <br/>}< br/>