当前位置 : 主页 > 编程语言 > python >

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

来源:互联网 收集:自由互联 发布时间:2023-03-22
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 directio

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

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 (   1uva 1030 - Image Is Everything(思维,4级)_#defineNuva 1030 - Image Is Everything(思维,4级)_#define10

). 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.2ZZ ZZ ZZ ZZ ZZ ZZZZ ZZ ZZ ZZ ZZ ZZ0

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

网友评论