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. Fragment之一:Fragment入门

    参考自张泽华视频 Fragment是自Android3.0后引入的特性,主要用于在不同的屏幕尺寸中展现不同的内容. Fragment必须被嵌入Activity中使用,总是作为Activity的组成部分 ...

  2. python运维开发(十一)----线程、进程、协程

    内容目录: 线程 基本使用 线程锁 自定义线程池 进程 基本使用 进程锁 进程数据共享 进程池 协程 线程 线程使用的两种方式,一种为我们直接调用thread模块上的方法,另一种我们自定义方式 方式一 ...

  3. codeforces 518A. Vitaly and Strings

    A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. 闲来瞎扯 -- 在vs2008下编写linux程序

    虽说vim很强大,但是个人感觉器代码提示功能不如visual assist来的强大.如何使用visual assist来实现代码的提示功能呢? 首先说明我的环境 : 宿主机是xp(O(∩_∩)O~还是 ...

  5. zabbix 组信息

    mysql> select * from groups; +---------+------------------+----------+-------+ | groupid | name | ...

  6. JIRA项目跟踪管理工具简介与安装

    1.什么是JIRA JIRA是Atlassian公司出品的项目与事务跟踪工具,被广泛应用于缺陷跟踪.客户服务.需求收集.流程审批.任务跟踪.项目跟踪和敏捷管理等工作领域. Atlassian2002年 ...

  7. 【LeetCode练习题】Reverse Linked List II

    Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...

  8. Python OpenGL学习(1): 环境配置及错误篇

    系统环境是:Ubuntu 14.04 个人首次接触OpenGL,学到哪就写到哪. 1.模块安装: sudo apt-get install python-openglpip install PyOpe ...

  9. 求职(2015南京站获得百度、美的集团、趋势科技、华为offer)

    版权所有所有:没有马缰绳chhuach(CSDN博客源).转载请注明出处. 禁止www.haogongju.net转载. 特此声明 一.开篇: 9月底,找工作接近尾声,笔者主要经历了2015年南京站百 ...

  10. SSCTF-PWN

    前几天比赛的PWN题,简单写了下. PWN400 漏洞是一个数组越界访问造成的任意地址读写.在对数据排序后,对数据进行查询和更新时,可以访问到数组以外一个元素(4个字节). 程序中存在3种数据结构,第 ...