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
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)
本题的重点在于一个坐标变换,刘汝佳的算法竞赛入门经典训练指南中有一种坐标变换方法是以前视图为正面完成的坐标变换,我在这里改变了建立坐标系的方法。
本题坐标变换的作用主要是将6个不同系的二维坐标平面对应到一个空间坐标系中。本题加方块是非常麻烦的,所以可以采取减去方块的方法,首先我们先假设坐标系中方块全都存在,然后枚举六个面的各个方块,检查目前的方式是不是满足视图,不满足则进行减方块操作。枚举6个视图之后即可得到我们想要的最优答案。
代码如下
#include<bits/stdc++.h>
using namespace std;
const int maxn=11;
char s[7][maxn][maxn];
char r[maxn][maxn][maxn];
int n;
void get(int k,int i,int j,int u,int &x,int &y,int &z){
if(k==0)x=n-1-u,y=j,z=n-1-i;
if(k==1)x=j,y=u,z=n-1-i;
if(k==2)x=u,y=n-j-1,z=n-1-i;
if(k==3)x=n-1-j,y=n-u-1,z=n-1-i;
if(k==4)x=i,y=j,z=n-1-u;
if(k==5)x=n-1-i,y=j,z=u;
//x-=1;y-=1;z-=1;
}
void show(){
for(int i=0;i<n;i++,puts("========"))
for(int j=0;j<n;j++,puts(""))
for(int k=0;k<n;k++)
cout<<r[i][j][k];
}
int main(){;
//int n;
while(scanf("%d",&n)==1&&n){
for(int j=0;j<n;j++){
for(int i=0;i<6;i++){
scanf("%s",s[i][j]);
}
}
/*for(int i=0;i<6;i++,puts("\n"))
for(int j=0;j<n;j++,puts(""))
for(int k=0;k<n;k++)
cout<<s[i][j][k];*/
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int u=0;u<n;u++)
r[i][j][u]='#';
for(int u=0;u<6;u++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
if(s[u][i][j]=='.'){
for(int k=0;k<n;k++){
int x,y,z;
get(u,i,j,k,x,y,z);
r[x][y][z]='.';
}
}
}
//show();
while(1){
int flg=1;
for(int i=0;i<6;i++)
for(int j=0;j<n;j++)
for(int k=0;k<n;k++){
if(s[i][j][k]!='.'){
//int flg=1;
for(int u=0;u<n;u++){
int x,y,z;
get(i,j,k,u,x,y,z);
if(r[x][y][z]=='.')continue;
if(r[x][y][z]=='#'){
r[x][y][z]=s[i][j][k];
break;
}
if(r[x][y][z]==s[i][j][k])break;
r[x][y][z]='.';
flg=0;
//cout<<"dsa"<<endl;
}
//if(!flg)break;
}
}
if(flg)break;
//show();
}
int ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
if(r[i][j][k]!='.')ans++;
printf("Maximum weight: %d gram(s)\n",ans);
}
}