LA 2995 & ZOJ2714 Image is Everything

原创 2015年07月09日 08:33:18
Image is Everything

Time Limit: 2 Seconds Memory Limit: 65536 KB

Your new company is building a robot that can hold small lightweight objects. The robot will have the intelligence to determine if an object is light enough to hold. It does this by taking pictures of the object from the 6 cardinal directions, and then inferring an upper limit on the object's weight based on those images. You must write a program to do that for the robot.

You can assume that each object is formed from an N*N*N lattice of cubes, some of which may be missing. Each 1*1*1 cube weighs 1 gram, and each cube is painted a single solid color. The object is not necessarily connected.

Input

The input for this problem consists of several test cases representing different objects. Every case begins with a line containing N, which is the size of the object (1 <= N <=10). The next N lines are the different N*N views of the object, in the order front, left, back, right, top, bottom. Each view will be separated by a single space from the view that follows it. The bottom edge of the top view corresponds to the top edge of the front view. Similarly, the top edge of the bottom view corresponds to the bottom edge of the front view. In each view, colors are represented by single, unique capital letters, while a period (.) indicates that the object can be seen through at that location.

Input for the last test case is followed by a line consisting of the number 0.

Output

For each test case, print a line containing the maximum possible weight of the object, using the format shown below.

Sample Input

3
.R. YYR .Y. RYY .Y. .R.
GRB YGR BYG RBY GYB GRB
.R. YRR .Y. RRY .R. .Y.
2
ZZ ZZ ZZ ZZ ZZ ZZ
ZZ ZZ ZZ ZZ ZZ ZZ
0

Sample Output

Maximum weight: 11 gram(s)
Maximum weight: 8 gram(s)

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define FOR(i,n) for(int i=1; i<=n; i++)
#define FORDAO(i,n) for(int i=n; i>0; i--)
const int MAXN = 15;
char view[MAXN][MAXN][MAXN][10];
bool islive[MAXN][MAXN][MAXN];
int n;
char read_char()
{
    char rt;
    while(true)
    {
        rt = getchar();
        if((rt>='A'&&rt<='Z') || rt=='.')return rt;
    }
}
void deleteone(int x, int y, int z)
{
    int a;
    for(a=1;!islive[x+a][y][z];a++);
    view[x+a][y][z][5] = view[x][y][z][5];
    for(a=1;!islive[x-a][y][z];a++);
    view[x-a][y][z][6] = view[x][y][z][6];
    for(a=1;!islive[x][y+a][z];a++);
    view[x][y+a][z][2] = view[x][y][z][2];
    for(a=1;!islive[x][y-a][z];a++);
    view[x][y-a][z][4] = view[x][y][z][4];
    for(a=1;!islive[x][y][z+a];a++);
    view[x][y][z+a][3] = view[x][y][z][3];
    for(a=1;!islive[x][y][z-a];a++);
    view[x][y][z-a][1] = view[x][y][z][1];
    islive[x][y][z] = false;
}
bool check(int x, int y, int z)
{
    char color='a';
    FOR(k,6)
    {
        if(view[x][y][z][k]=='.')return false;
        if(view[x][y][z][k]=='a')continue;
        if(view[x][y][z][k]==color || color=='a')
        {
            color = view[x][y][z][k];   
        }else{
            return false;
        }
    } 
    return true;
}
bool work()
{
    bool rt = false;
    FOR(x,n) FOR(y,n) FOR(z,n)
    if(islive[x][y][z] && !check(x,y,z))
    {
        deleteone(x,y,z);
        rt = true;
    }
    return rt;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)break;
        FOR(x,n)FOR(y,n)FOR(z,n)FOR(k,6)view[x][y][z][k] = 'a';
        memset(islive,1,sizeof islive);
        FOR(x,n)
        {
             FOR(y,n) view[x][y][1][3] = read_char();
             FORDAO(z,n) view[x][1][z][2] = read_char();
             FORDAO(y,n) view[x][y][n][1] = read_char();
             FOR(z,n) view[x][n][z][4] = read_char();
             FOR(y,n) view[1][y][n-x+1][5] = read_char();
             FOR(y,n) view[n][y][x][6] = read_char(); 
        }
         
        while(work());
        int ans = 0;
        FOR(i,n) FOR(j,n) FOR(k,n) 
        if(islive[i][j][k]) ans++;
        printf("Maximum weight: %d gram(s)\n",ans); 
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

la 2995 Image is everything

题目链接:点击打开链接 题目大意:有一个n*n*n的立方体,其中一些立方体已经缺失.每个单位立方体重量为1克,且被涂上单一的颜色.给出前,后,左,右,顶,底6个视图,判断这个立方体剩下的最大可能...

UVaLive-2995 Image Is Everything

题目描述: 给一个N*N*N的立方体(可以缺少某几块)的六个视图,依次为前、左、后、右、顶、底视图。“."代表可以看透,其他字母代表颜色。每一小方块各个面颜色相同。问这个物体的最大质量。直到读取的N...

UVALive 2995 Image Is Everything 策略问题

#include #include #include #include using namespace std; char pos[10][10][10]; char view[6][10][...

UVA 1030 - Image Is Everything(贪心枚举)

Description Your new company is building a robot that can hold small lightweight objects. The rob...

UVA 1030 Image Is Everything

刘汝佳大神书上的原题,思路是寻找六个视图中颜色的冲突,只要

World Finals 2004 / UVa 1030 Image Is Everything (想法题&迭代更新)

1030 - Image Is Everything Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com...

uvaoj 1030 - Image Is Everything

总结: 1.以前看过汝佳哥源代码,没有打在电脑里提交,自以为会了,最近重新做题的时候才发现原来只是看懂了,自己并不能很快的思考出来这个问题,以后凡是碰到代码,尽所能付诸于实践!以写代码,写博客的形式...

【简单题】【综合能力】UVA-1030-Image Is Everything

题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_pro...

Uva 1030 - Image Is Everything

方法: 建立空间直角坐标系,把六个视角看到的投影到坐标系中,看六个视角看到的是否会有冲突,有冲突代表改点不存在 PS: 某渣实在是不想吐槽了,初始化的是把.写成了*  特么害我一直以为我坐标系建错了...

uva 1030 Image Is Everything(迭代更新)

uva 1030 Image Is Everything Your new company is building a robot that can hold small lightwe...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)