Puzzle


Time Limit: 2 Seconds       Memory Limit: 65536 KB


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 drawn on his surface.

The interesting fact about that triangle is that it is not solid - it consists of two parts. Each of the parts is a connected set of unit triangles. Georgie has put his triangle onto the table and now wonders whether he can separate the parts. He wants to separate them without taking any part of the triangle off 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 can separate the parts the way he wants. However in the case displayed on the bottom picture, he cannot separate 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.

                                                                    

ZOJ—2610_ide

ZOJ—2610_i++_02

Two puzzles corresponding the samples

Input

Input file contains one or more testcases. The first line of each testcase contains n (2 <= n <= 50). Next n lines contain the description of the triangle, i-th of these lines contains 2i - 1 characters, describing unit triangles in the i-th row, from left to right. Character '0' means that the triangle belongs to the first part of the main triangle, '1' means that it belongs to the second one.

Testcase with n = 0 designates the end of the test data, this testcase 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 can be separated. Do not output any blank lines.


Sample Input

60 001 00011 0000011 000111111 00111111111 6 0 001 00111 0011011 000000111 00111111111 0


Sample Output

Puzzle 1Parts can be separated Puzzle 2 Parts cannot be separated

【分析】
瞎搞的题目....题意就是给你一个很多小三角组成的三角形,这个三角形由两部分组成,问你能不能把这两部分拉开。
就是三个平行线方向,看能不能分开就可以了,每行中01相交的次数最多只能是1次,否则就拉不开,三角形转两次,判断一下就好了...
【代码】

#include<iostream>  
#include<cstdio>
#include<cstring>
using namespace std;
char s[70][140];
char ss[70][140];
int n;
int judge()
{
for(int i=0;i<n;i++)
{
int t=0;
for(int j=0;j<2*i;j++)
if(s[i][j]!=s[i][j+1])
{
t++;
if (t>1) return 0;
}
}
return 1;
}
int main()
{
int pp=1;
while(~scanf("%d",&n)&&n)
{
getchar();
for(int i=0;i<n;i++) scanf("%s",s[i]);
printf("Puzzle %d\n",pp++);
int xx=judge();
if (xx)
{
printf("Parts can be separated\n");
continue;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
ss[i][2*j]=s[n-j-1][2*(i-j)];
ss[i][2*j+1]=s[n-j-1][2*(i-j)-1];
}
ss[i][2*i]=s[n-i-1][0];
ss[i][2*i+1]='\0';
}
for(int i=0;i<n;i++)for (int j=0;j<=2*i+1;j++) s[i][j]=ss[i][j];
//for(int i=0;i<n;i++) printf("%s\n",s[i]);
xx=judge();
if (xx)
{
printf("Parts can be separated\n");
continue;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
ss[i][2*j]=s[n-j-1][2*(i-j)];
ss[i][2*j+1]=s[n-j-1][2*(i-j)-1];
}
ss[i][2*i]=s[n-i-1][0];
ss[i][2*i+1]='\0';
}
for(int i=0;i<n;i++)for (int j=0;j<=2*i+1;j++) s[i][j]=ss[i][j];
xx=judge();
if (xx)
{
printf("Parts can be separated\n");
continue;
}
printf("Parts cannot be separated\n");
}
return 0;
}