uva 1030 - Image Is Everything(思维,4级)

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$ \le$N$ \le$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<cstring>
#include<cstdio>
#define FOR(i,n) for(int i=0;i<n;++i)
using namespace std;
const int mm=15;
char vis[mm][mm][mm],g[mm][mm][mm],view[mm][mm][mm];
char read_char()
{
  char s;
  while(1)
  {
    s=getchar();
    if(s>='A'&&s<='Z')return s;
    if(s=='.')return s;
  }
}
int n;
void get(int a,int b,int c,int len,int&x,int&y,int&z)
{ ///前左顶x,y,z
  if(a==0){x=len;y=c;z=b;}
  else if(a==1){x=n-c-1;y=len;z=b;}
  else if(a==2){x=n-len-1;y=n-c-1;z=b;}
  else if(a==3){x=c;y=n-len-1;z=b;}
  else if(a==4){x=n-b-1;y=c;z=len;}
  else if(a==5){x=b;y=c;z=n-len-1;}
}
int main()
{ int x,y,z;
  while(scanf("%d",&n)&&n)
  { FOR(i,n)FOR(j,n)FOR(k,n)vis[i][j][k]='#';
    FOR(i,n)FOR(k,6)FOR(j,n)g[k][i][j]=read_char();
    FOR(k,6)FOR(i,n)FOR(j,n)
    if(g[k][i][j]=='.')///能看穿
    {
      FOR(p,n)
      {get(k,i,j,p,x,y,z);///得到对应的内部点
       vis[x][y][z]='.';
      }
    }
    while(1)
    { bool flag=1;
    FOR(k,6)FOR(i,n)FOR(j,n)
    if(g[k][i][j]!='.')
    {
      FOR(p,n)
      {
        get(k,i,j,p,x,y,z);///得到立方体位置
        if(vis[x][y][z]=='#'){vis[x][y][z]=g[k][i][j];flag=0;break;}
        if(vis[x][y][z]=='.')continue;
        if(vis[x][y][z]==g[k][i][j])break;///符合看不见的条件
        if(vis[x][y][z]!=g[k][i][j]){vis[x][y][z]='.';flag=0;}///不符合说明没这块
      }
    }
    if(flag)break;///不可再消了,结束
   }
   int ans=0;
   FOR(i,n)FOR(j,n)FOR(k,n)
   if(vis[i][j][k]!='.')++ans;
   printf("Maximum weight: %d gram(s)\n",ans);
  }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值