TOJ 2560 Geometric Shapes(鍒ゆ柇澶氳竟褰㈡槸鍚︾浉浜?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TOJ 2560 Geometric Shapes(鍒ゆ柇澶氳竟褰㈡槸鍚︾浉浜?相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/div' title='div'>div
鎻忚堪 wing nbsp geo sum rip order amp鎻忚堪
While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be cut into special fluorescent materials. To ensure proper processing, the shapes in the picture cannot intersect. However, some logos contain such intersecting shapes. It is necessary to detect them and decide how to change the picture.
Given a set of 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 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 the
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 (鈥?鈥?.
杈撳嚭
For each picture, output one line for each of the shapes, sorted alphabetically by its identifier (X). The line must be one of the following:
? 鈥淴 has no intersections鈥? if X does not intersect with any other shapes.
? 鈥淴 intersects with A鈥? if X intersects with exactly 1 other shape.
? 鈥淴 intersects with A and B鈥? if X intersects with exactly 2 other shapes.
? 鈥淴 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.
鏍蜂緥杈撳叆
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)
-
.
鏍蜂緥杈撳嚭
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
棰樻剰
缁欎綘澶氳竟褰紝濡傛灉鍦ㄥ唴閮ㄥ垯瑙嗕负涓嶇浉浜わ紝鍒ゆ柇鍝簺鏄浉浜ょ殑
棰樿В
鎶婂杈瑰舰鎸夎竟瀛橈紝濡傛灉涓や釜澶氳竟褰㈢浉浜わ紝閭d箞涓€瀹氬瓨鍦ㄤ袱鏉¤竟鐩镐氦
鍒ゆ柇涓ゆ潯杈圭浉浜わ紝鍏堢敤淇╃煩褰㈠揩閫熸帓鏂ワ紝鍐嶇敤璺ㄧ珛瀹為獙锛屽鏋渁b鍜宑d鐩镐氦锛岄偅涔坈d鐨勪袱绔竴瀹氬湪鍚戦噺ab鐨勪袱渚э紝鍙互閫氳繃abc鍜宎bd鍙夌Н鐩镐箻<0鍒ゆ柇鏄惁鐩镐氦
鐒跺悗灏辨槸瀛樺杈瑰舰锛岃繖閲屾鏂瑰舰鍜岀煩褰㈠彟澶栫殑鐐瑰緱閫氳繃鍚戦噺璁$畻涓€涓?/span>
PS锛氱爜鍐滈锛岃杈撳叆锛岃緭鍑洪兘鎭跺績锛岄鐩笉绠楀お闅?/span>
浠g爜
1 #include<cstdio> 2 #include<algorithm> 3 #include<vector> 4 #include<set> 5 using namespace std; 6 struct point 7 { 8 double x,y; 9 point(double x=0,double y=0):x(x),y(y){} 10 }; 11 bool judge(point a,point b,point c,point d) 12 { 13 if(!(min(a.x,b.x)<=max(c.x,d.x)&&min(c.y,d.y)<=max(a.y,b.y)&&min(c.x,d.x)<=max(a.x,b.x)&&min(a.y,b.y)<=max(c.y,d.y))) 14 return false; 15 double u,v,w,z; 16 u=(c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); 17 v=(d.x-a.x)*(b.y-a.y)-(b.x-a.x)*(d.y-a.y); 18 w=(a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y); 19 z=(b.x-c.x)*(d.y-c.y)-(d.x-c.x)*(b.y-c.y); 20 return (u*v<=0.00000001&&w*z<=0.00000001); 21 } 22 vector<point>G[27]; 23 24 int main() 25 { 26 //freopen("A.txt","w",stdout); 27 int m; 28 double a,b; 29 char op[3],shape[20]; 30 while(scanf("%s",op)!=EOF,op[0]!=鈥?/span>.鈥?/span>) 31 { 32 for(int i=0;i<26;i++)G[i].clear(); 33 while(op[0]!=鈥?/span>-鈥?/span>) 34 { 35 int cnt=op[0]-鈥?/span>A鈥?/span>; 36 scanf("%s",shape); 37 if(shape[0]==鈥?/span>s鈥?/span>)///姝f柟褰?/span> 38 { 39 for(int i=1;i<=2;i++) 40 { 41 scanf(" (%lf,%lf)",&a,&b); 42 G[cnt].push_back(point(a,b)); 43 } 44 double A=G[cnt][0].x,B=G[cnt][0].y,C=G[cnt][1].x,D=G[cnt][1].y; 45 G[cnt].push_back(point((A*1.0+B+C-D)/2.0,(-A*1.0+B+C+D)/2.0)); 46 G[cnt].push_back(point((A*1.0-B+C+D)/2.0,(A*1.0+B-C+D)/2.0)); 47 swap(G[cnt][1],G[cnt][2]); 48 G[cnt].push_back(G[cnt][0]); 49 } 50 if(shape[0]==鈥?/span>r鈥?/span>)///鐭╁舰 51 { 52 for(int i=1;i<=3;i++) 53 { 54 scanf(" (%lf,%lf)",&a,&b); 55 G[cnt].push_back(point(a,b)); 56 } 57 G[cnt].push_back(point(G[cnt][0].x*1.0+G[cnt][2].x-G[cnt][1].x,G[cnt][0].y*1.0+G[cnt][2].y-G[cnt][1].y)); 58 G[cnt].push_back(G[cnt][0]); 59 } 60 if(shape[0]==鈥?/span>l鈥?/span>)///绾?/span> 61 { 62 for(int i=1;i<=2;i++) 63 { 64 scanf(" (%lf,%lf)",&a,&b); 65 G[cnt].push_back(point(a,b)); 66 } 67 } 68 if(shape[0]==鈥?/span>t鈥?/span>)///涓夎褰?/span> 69 { 70 for(int i=1;i<=3;i++) 71 { 72 scanf(" (%lf,%lf)",&a,&b); 73 G[cnt].push_back(point(a,b)); 74 } 75 G[cnt].push_back(G[cnt][0]); 76 } 77 if(shape[0]==鈥?/span>p鈥?/span>)///澶氳竟褰?/span> 78 { 79 scanf("%d",&m); 80 for(int i=1;i<=m;i++) 81 { 82 scanf(" (%lf,%lf)",&a,&b); 83 G[cnt].push_back(point(a,b)); 84 } 85 G[cnt].push_back(G[cnt][0]); 86 } 87 scanf("%s",op); 88 } 89 for(int i=0;i<26;i++) 90 { 91 int flag=0; 92 set<int>SET; 93 if((int)G[i].size()==0)continue; 94 for(int j=0;j<(int)G[i].size()-1;j++) 95 { 96 for(int k=0;k<26;k++) 97 { 98 if((int)G[k].size()==0||i==k)continue; 99 for(int l=0;l<(int)G[k].size()-1;l++) 100 { 101 if(judge(G[i][j],G[i][j+1],G[k][l],G[k][l+1])) 102 { 103 flag=1; 104 SET.insert(k); 105 break; 106 } 107 } 108 } 109 } 110 if(flag==1) 111 { 112 vector<int>VEC(SET.begin(),SET.end()); 113 int len=(int)VEC.size(); 114 printf("%c intersects with",i+鈥?/span>A鈥?/span>); 115 if(len==2) 116 {printf(" %c and %c ",VEC[0]+鈥?/span>A鈥?/span>,VEC[1]+鈥?/span>A鈥?/span>);continue;} 117 for(int l=0;l<len-1;l++) 118 printf(" %c,",VEC[l]+鈥?/span>A鈥?/span>); 119 if(len>1) 120 printf(" and %c",VEC[len-1]+鈥?/span>A鈥?/span>); 121 else 122 printf(" %c",VEC[len-1]+鈥?/span>A鈥?/span>); 123 printf(" "); 124 } 125 else 126 printf("%c has no intersections ",i+鈥?/span>A鈥?/span>); 127 } 128 printf(" "); 129 } 130 return 0; 131 }