UVA 1030 Image Is Everything

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)


本题的重点在于一个坐标变换,刘汝佳的算法竞赛入门经典训练指南中有一种坐标变换方法是以前视图为正面完成的坐标变换,我在这里改变了建立坐标系的方法。

本题坐标变换的作用主要是将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);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值