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. 初识ege图形库

    简介: EGE (Easy Graphics Engine),是Windows 下的简易绘图库, 是一个类似BGI (graphics.h)的 面向C/C++语言新手的图形库,对新手来说,简单,友好, ...

  2. G - Bullseye

    Description A simple dartboard consists of a flat, circular piece of cork with concentric rings draw ...

  3. 深入理解JavaWeb技术内幕(一)

    最近在看许令波的<深入理解JavaWeb技术内幕>.整理了一些笔记.想做一个系列,这篇是系列的第一篇,讲Web请求. B/S架构 最常见的架构方式. 优点: 1.客户端使用统一(此处的统一 ...

  4. RMAN之一:快速入门

    1.数据导出基础 (1)创建datapump导出文件的目录对象并为相应用户授予权限. 出于安全考虑,不允许oracle用户直接在OS上进行文件的操作,而应通过directory对象指定. SQL> ...

  5. js 数组排除重复值(string)

    前提:数组中的元素类型为:string 在网上看了许多高大尚的文章,还是解决不了我的string arry 的问题,只能怪自己脑残了,上代码: <!DOCTYPE html> <ht ...

  6. 简单的Mvp设计

    任务:从网络上获取数据,然后显示在MainActivity的ListView上 一.载入需要用的框架 1.Mvp框架 compile 'com.hannesdorfmann.mosby:mvp:2.0 ...

  7. 微软云基础架构Hyper-scale Datacenter

    每天醒来,可能很多人的习惯都是打开手机,看看微信,刷刷朋友圈,或者看看新闻,去咖啡店,打开电脑搜索一些关键字,观看视频,电视剧--可是你有没有想过你每一次键盘的敲击,每一次微信的语音的发送,数据会流向 ...

  8. Nginx 教程的连载计划

    下面以教程系列为单位,列举出了已经发表和计划发表的连载教程: Nginx 新手起步 Nginx 是如何匹配 URI 的 Nginx 变量漫谈 Nginx 配置指令的执行顺序 Nginx 的 if 是邪 ...

  9. Mongo客户端

    http://www.linuxidc.com/Linux/2012-07/64233.htm http://www.oschina.net/p/rockmongo http://www.cnblog ...

  10. 【hihocoder 1249 Xiongnu's Land】线性扫描

    2015区域赛北京赛区的三水,当时在赛场上没做出的原因是复杂度分析不正确导致把方法想复杂了.近来复习复杂度分析,觉得不能只是笼统地看渐进复杂度(big-O),更应根据算法的伪码计算真正的以基本操作数为 ...