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. Linq to DataSet 和 DataSet使用方法学习

    简单入门: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...

  2. 简单的Mvp设计

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

  3. Linux下MySQL安装及命令使用

    先rpm -qa mysql 查看是否安装 yum list |grep mysql 查看MySQL的一些包 yum install -y mysql-server mysql mysql-devel ...

  4. 10年程序员谈.Net程序员的职业规划(图/文)

    原文地址:http://bbs.csdn.net/topics/390736769 从事Dotnet程序开发工作近10年了,从开始的月薪3k的小程序员菜鸟,到现在年薪60w的项目总经理,从战战兢兢的去 ...

  5. Wikioi 1294 全排列

    先给出链接地址:Wikioi 1294 虽然题目很短,论难度也就是个深搜,算法方面我就不多说了,而且我知道c++有个函数叫next_permutation,谁用谁知道. 代码如下: #include& ...

  6. 移动端页面SEO优化需要注意的10个要点

    如今,移动互联网已经成为互联网组成的非常重要的一个分支,如果说以前对移动页面没有很规范的优化和高质量内容评判划分标准,但现在随着各大搜索引擎发布了移动建站指南,图文并茂的描述了如何提高移动站在百度质量 ...

  7. C++求二叉树的最大高度差

    #include <iostream> #include <string.h> using namespace std; template<typename Type&g ...

  8. phonegap开发app中踩过的那些坑

    把遇到的问题列出来,假设有解决方式的,偶也会写下来.假设大家有更好解决方法的.欢迎留言噢 phonegap 2.9无法触发deviceready事件 亲们能够看下控制台有木有报错.假设有提示cordo ...

  9. oracle的内存管理(之中的一个)

    [深入解析oracle-eygle]学习笔记 1.内存管理 ORACLE数据库所使用的内存主要涉及到两个方面:PGA和SGA. 1.1 PGA管理 PGA指的是程序全局区(Program Global ...

  10. android 中动画

    详解Android动画之Frame Animation 写出动画效果的xml文件布局基本代码如下: <?xml version="1.0" encoding="ut ...