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;
}


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

持续集成--“Everything is code”

在前文《软件自我识别》中,我们讨论了如果使软件做到自我识别,以促进自动化部署和版本检测等工作。 随着互联网的飞速发展,以及基础设施的改进,越来越多的业务被放在了“云”端。管理数千台服务器和各种应用程序...
  • xifeijian
  • xifeijian
  • 2013年10月16日 00:57
  • 2028

简陋,山寨,Everything,桌面搜索,原理,源码

出处:http://hi.baidu.com/chenxiong0115/blog/item/b31e573a3d8bd6e715cecbb6.html   前些时间对Everything很感兴趣,...
  • qq_16542775
  • qq_16542775
  • 2016年08月30日 15:06
  • 1477

Everything 1.3.4.686 官方多国语言安装版(含简体中文版 瞬间搜索整个硬盘文件)

NTFS 文件系统下最快的文件搜索工具!文件搜索工具有不少,如Ava Find Pro,Locate32,File Seeker 等,但要说速度最快的,还非 Everything 莫属。与其它的搜索工...
  • andyhebear
  • andyhebear
  • 2015年09月23日 12:37
  • 1422

la 2995 Image is everything

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

UVALive 2995 Image Is Everything 策略问题

#include #include #include #include using namespace std; char pos[10][10][10]; char view[6][10][...
  • a601025382s
  • a601025382s
  • 2013年07月17日 10:50
  • 735

UVaLive-2995 Image Is Everything

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

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...
  • synapse7
  • synapse7
  • 2013年09月01日 20:58
  • 1012

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

Description Your new company is building a robot that can hold small lightweight objects. The rob...
  • u013534690
  • u013534690
  • 2014年10月05日 11:23
  • 393

UVA 1030 Image Is Everything

刘汝佳大神书上的原题,思路是寻找六个视图中颜色的冲突,只要
  • xiaohaowudi
  • xiaohaowudi
  • 2014年06月07日 00:12
  • 247

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

题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_pro...
  • u013303743
  • u013303743
  • 2014年06月06日 21:23
  • 902
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LA 2995 & ZOJ2714 Image is Everything
举报原因:
原因补充:

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