Plato's Blocks
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 734   Accepted: 296

Description

Plato believed what we perceive is but a shadow of reality. Recent archaeological excavations have uncovered evidence that this belief may have been encouraged by Plato's youthful amusement with cleverly-designed blocks. The blocks have the curious property that, when held with any face toward a light source, they cast shadows of various letters, numbers, shapes, and patterns. It is possible for three faces incident to a corner to correspond to three different shadow patterns. Opposite faces, of course, cast shadows which are mirror images of one another. 
The blocks are formed by gluing together small cubes to form a single, connected object. As an example, the figures below show, layer by layer, the internal structure of a block which can cast shadows of the letters "E", "G", or "B". 

Only a partial set of blocks was discovered, but the curious scientists would like to determine what combinations of shadows are possible. Your program, the solution to this problem, will help them! The program will input groups of shadow patterns, and for each group will report whether or not a solid can be constructed that will cast those three shadows. 

Input

The input contains a sequence of data sets, each specifying a dimension and three shadow patterns. The first line of a data set contains a positive integer 1 <= n <= 20 that specifies the dimensions of the input patterns. The remainder of the data set consists of 3n lines, each containing a string of n "X" and "-" characters. Each group of n lines represents a pattern. Where an "X" appears a shadow should be cast by the final solid, and where a "-" appears, light should pass through. For this problem, the input patterns may be assumed to have at least one "X" along each edge of the pattern. The input is terminated by a line containing a single zero in place of a valid dimension. 

Output

For each data set in the input, output the data set number and one of the following messages:

Valid set of patterns 
Impossible combination 
For a set of patterns to be considered valid, it must be possible to construct, by gluing unit cubes together along their faces, a one-piece solid capable of casting the shadow of each of the input patterns. 

Sample Input

5
XXXXX
X----
X--XX
X---X
XXXXX
XXXXX
X----
XXXXX
X----
XXXXX
XXXXX
X---X
XXXX-
X---X
XXXXX
3
X--
-X-
--X
XX-
XXX
-XX
-XX
XXX
XX-
0

Sample Output

Data set 1: Valid set of patterns
Data set 2: Impossible combination 这个问题刚开始没有思路,看了网上的一些方法,就自己写了一个;
 //注意每个面都由八种方式,旋转+翻转
//先建一个完整的立方块,然后删去中间的空缺部分
//最后检查一下(深搜)是不是所有的小立方块都连在一起 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio> using namespace std;
char mpr[][];
int n;
char mp[][][][];
char cube[][][];
int dx[]={,,,,,-};
int dy[]={,,,-,,};
int dz[]={,-,,,,};
void cs(int t)
{
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mpr[i][j];
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mp[t][][i][n--j];
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mp[t][][j][n--i];
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mp[t][][i][n--j];
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mp[t][][j][n--i];
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mp[t][][i][n--j];
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mp[t][][j][n--i];
for(int i=;i<n;i++)
for(int j=;j<n;j++)
mp[t][][i][j]=mp[t][][i][n--j];
}
int checkview1(int a)
{
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
if(mp[][a][i][j]=='X')
{
int flag=;
for(int k=;k<n;k++)
if(cube[i][j][k]==)
flag=;
if(flag==) return ;
}
}
return ;
}
int checkview2(int a)
{
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
if(mp[][a][i][j]=='X')
{
int flag=;
for(int k=;k<n;k++)
if(cube[i][k][j]==)
flag=;
if(flag==) return ;
}
}
return ;
}
int checkview3(int a)
{
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
if(mp[][a][i][j]=='X')
{
int flag=;
for(int k=;k<n;k++)
if(cube[k][i][j]==)
flag=;
if(flag==) return ;
}
}
return ;
}
int check(int x,int y,int z)
{
if(x<n&&x>=&&y<n&&y>=&&z<n&&z>=) return ;
return ;
}
void dfs(int a,int b,int c)
{
for(int i=;i<;i++)
{
int curx=a+dx[i];
int cury=b+dy[i];
int curz=c+dz[i];
if(check(curx,cury,curz)&&cube[curx][cury][curz]==)
{
cube[curx][cury][curz]=;
dfs(curx,cury,curz);
}
}
return ;
}
int Num()
{
int num=;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
for(int k=;k<n;k++)
if(cube[i][j][k]==)
{
cube[i][j][k]=;
dfs(i,j,k);
num++;
}
if(num>) return ;
return ;
}
int solve(int a,int b,int c)
{
//建一个完全的立方块
memset(cube,,sizeof(cube)); //删去其中的空缺部分
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(mp[][a][i][j]=='-')
for(int k=;k<n;k++)
cube[i][j][k]=;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(mp[][b][i][j]=='-')
for(int k=;k<n;k++)
cube[i][k][j]=;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(mp[][c][i][j]=='-')
for(int k=;k<n;k++)
cube[k][i][j]=; //检查三视图是否还是符合的还有立方块是否都连在一起(dfs)
if(checkview1(a)&&checkview2(b)&&checkview3(c)&&Num())
return ;
return ;
}
int main()
{
int num=;
while(cin >> n&&n)
{
for(int i=;i<;i++)
{
for(int j=;j<n;j++)
cin >> mpr[j];
cs(i);//这里构建八个面,那么8*8*8=512种情况,只要有一种情况符合就行了
}
int flag=;
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
if(solve(i,j,k))//检查每种情况是否符合
flag=;
if(flag)
printf("Data set %d: Valid set of patterns\n",num++);
else printf("Data set %d: Impossible combination\n",num++);
}
return ;
}

POJ 1052 Plato's Blocks的更多相关文章

  1. POJ1052 Plato's Blocks

    题目来源:http://poj.org/problem?id=1052 题目大意: 把1*1*1的小立方体通过粘接相邻面组成大的立方体的形状.如下图所示: 一层一层地堆叠,立方体从三个方向的投影会分别 ...

  2. POJ 1609 Tiling Up Blocks

    Tiling Up Blocks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4675   Accepted: 1824 ...

  3. POJ 1052 MPI Maelstrom

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5547   Accepted: 3458 Des ...

  4. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

  5. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  6. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  7. 专题:DP杂题1

    A POJ 1018 Communication System B POJ 1050 To the Max C POJ 1083 Moving Tables D POJ 1125 Stockbroke ...

  8. poj 1390 Blocks

    poj 1390 Blocks 题意 一排带有颜色的砖块,每一个可以消除相同颜色的砖块,,每一次可以到块数k的平方分数.问怎么消能使分数最大.. 题解 此题在徐源盛<对一类动态规划问题的研究&g ...

  9. [POJ 3734] Blocks (矩阵高速幂、组合数学)

    Blocks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3997   Accepted: 1775 Descriptio ...

随机推荐

  1. GYP构建系统总结

    GYP,Generate Your Project,一个Google开源的构建系统,最开始用于Chromium项目,现在一些其他的开源项目也开始使用GYP,如v8和node-gyp.不管怎样,这仅仅是 ...

  2. PHP截取汉字乱码问题解决方法mb_substr函数的应用

    首先 1.确保你的Windows/system32下有php_mbstring.dll这个文件,没有就从你Php安装目录extensions里拷入Windows/system32里面. 2.在wind ...

  3. Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout,TableLayout引起页面崩溃

    在使用TableLayout的时候,运行引用程序直接Crash. FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 9703 java. ...

  4. windows系统npm如何升级自身

    其实使用npm升级各种插件是很方便的,比如我想升级express框架,使用如下命令 npm update express 如果你的express是全局安装,则 npm update -g expres ...

  5. IBM Minus One(water)

    IBM Minus One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. Wolf and Rabbit(gcd)

    Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小 错误分析

    目录(?)[+] 1. 问题起因 最近在进行Oracle的一些操作时,总会遇到这个错误:  ORA-06502: PL/SQL: 数字或值错误 :  字符串缓冲区太小,错误如下: ORA-00604: ...

  8. MFC 动态创建按钮

    首先在对话框(模式对话框,无模式对话框)中添加一个ADD按钮,通过点击按钮产生的通告消息调用::OnBtnAdd()方法.此方法会在对话框的左上角创建一个按钮. 当然首先要在和次对话框相关联的类中添加 ...

  9. boost的并发库

    thread: http://www.boost.org/doc/libs/1_61_0/libs/thread/ asio: http://www.boost.org/doc/libs/1_61_0 ...

  10. VC++自绘界面

    // MySkinDlg.cpp : implementation file // #include "stdafx.h" #include "MySkin.h" ...