Little Georgie likes puzzles very much. Recently he has found a wooden triangle in the box with old toys.The side of the triangle is n inches long. The triangle is divided into n2 unit triangles with lines drawnon his surface.
The interesting fact about that triangle is that it is not solid - it consists of two parts. Each of theparts is a connected set of unit triangles. Georgie has put his triangle onto the table and now wonderswhether he can separate the parts. He wants to separate them without taking any part of the triangleoff the table, just moving the parts by the table surface. The triangle has a small but non-zero thickness,so while being moved the parts must not intersect.
For example, if the triangle is divided into parts as it is shown on the top picture below, Georgie canseparate the parts the way he wants. However in the case displayed on the bottom picture, he cannotseparate the parts without lifting one of them.
Help Georgie to determine whether he can separate the parts moving them by the surface of the table.
![]() | ![]() |
Input
Input file contains one or more testcases. The first line of each testcase contains n (2 <= n <= 50). Next nlines contain the description of the triangle, i-th of these lines contains 2i - 1 characters, describing unittriangles in the i-th row, from left to right. Character '0' means that the triangle belongs to the firstpart of the main triangle, '1' means that it belongs to the second one.
Testcase with n = 0 designates the end of the test data, thistestcase must not be processed. There is no blank line in the input file.
Output
For each puzzle output the line with its number followed by the line that states whether the parts canbe separated. Do not output any blank lines.
Sample Input
6 0 001 00011 0000011 000111111 00111111111 6 0 001 00111 0011011 000000111 00111111111 0
Sample Output
Puzzle 1 Parts can be separated Puzzle 2 Parts cannot be separated 题意: 一个三角形由两部分组成 问是否能同过向两边平移将其分开 代码:#include<iostream> #include<cstdio> #include<cstring> using namespace std; string q[55]; int m; void rotate() //旋转 { string rq[55]; int i,j; for(i=0;i<m;i++) { for(j=0;j<i;j++) { rq[i]+=q[m-j-1][2*(i-j)]; rq[i]+=q[m-j-1][2*(i-j)-1]; } rq[i]+=q[m-i-1][0]; } for(i=0;i<m;i++) { q[i]=rq[i]; } return; } int judge() { int i,j,s; for(i=0; i<m; i++) { s=0; for(j=0; j<2*i; j++) { if((q[i][j]=='0'&&q[i][j+1]=='1')||(q[i][j]=='1'&&q[i][j+1]=='0')) //0 1相间超过两次 这这个方向的三角形不能达到条件 s++; } if(s>1) return 0; } return 1; } int main() { int i,j; int tt=0; int ans1,ans2,ans3; while(~scanf("%d",&m)) { tt++; ans1=ans2=ans3=0; if(m==0) break; for(i=0; i<m; i++) cin>>q[i]; ans1=judge(); rotate(); ans2=judge(); rotate(); ans3=judge(); // cout<<ans1<<' '<<ans2<<' '<<ans3<<endl; cout<<"Puzzle "<<tt<<endl; if(ans1||ans2||ans3) cout<<"Parts can be separated"<<endl; else cout<<"Parts cannot be separated"<<endl; } return 0; }