zoj2610 Puzzle 数组转置,...

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.

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 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;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值