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. Java三大特征之封装(一)

    封装从字面上来理解就是包装的意思,专业点就是信息隐藏,是指利用抽象数据类型将数据和基于数据的操作封装在一起,使其构成一个不可分割的独立实体,数据被保护在抽象数据类型的内部,尽可能地隐藏内部的细节,只保 ...

  2. Centos7安装JDK

    以下是gz包方式: 1,将jdk-8u51-linux-x64.tar.gz放到/usr/java目录下 2,用tar -zxvf jdk-8u51-linux-x64.tar.gz 解压到当前目录 ...

  3. 【Android 错误记录】android.os.NetworkOnMainThreadException 异常问题

    最近自己学习开发一个小app,想根据网络来判断一些逻辑,但是运行应用时遇到了这个错误 android.os.NetworkOnMainThreadException 后来,查询了一些信息,发现原因就是 ...

  4. activiti 部署在oracle多用户下不能自动建表问题的解决!

    在activiti配置文件中的SpringProcessEngineConfiguration的配置项中添加<property name= "databaseSchema" ...

  5. AngularJS中serivce,factory,provider的区别

    一.service引导 刚开始学习Angular的时候,经常被误解和被初学者问到的组件是 service(), factory(), 和 provide()这几个方法之间的差别.This is whe ...

  6. php 代码重用

    <?php /* 21.php * 代码重用 * include() required()载入文件 * include() 如果载入文件不存在,提示警告,还可以继续执行 * required() ...

  7. 多线程 NSThread GCD

    ios多线程实现种类 NSThread NSOperationQueue NSObject GCD *************** 1.NSThread //线程 第一种 NSThread *thre ...

  8. 怎么让一个非窗口组件可以接受来自Windows的消息

    为什么要这样做? 有时候我们需要一个非窗口组件(比如一个非继承自TWinContrl的组件)可以接受Windows消息.要接受消息就需要一个窗口句柄,但是非窗口组件却没有句柄.这篇文章将讲述怎么让一个 ...

  9. Qt-4.6动画Animation快速入门三字决

    Qt-4.6动画Animation快速入门三字决 Qt-4.6新增了Animation Framework(动画框架),让我们能够方便的写一些生动的程序.不必像以前的版本一样,所有的控件都枯燥的呆在伟 ...

  10. poj1458 dp入门

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37551   Accepted: 15 ...