UVA 2995立方体成像(Image is Everything)

题目:https://vjudge.net/problem/UVALive-2995

LRJ的方法妙,代码写的更妙..通过控制深度,从一个面就可以搜索到立方体的任意位置。运用的思想是观察到的颜色是否和

实际的立方块颜色矛盾不矛盾

他的代码是这么建系的:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)

const int maxn=10;
int n;
char pos[maxn][maxn][maxn];
char view[6][maxn][maxn];

char read_char(){
	char ch;
	for(; ;){
		ch=getchar();
		if((ch>='A' && ch<='Z') || ch=='.')
		return ch;
	}
}

void get(int k,int i,int j,int len,int &x,int &y,int &z){
	if(k==0){x=len;y=j;z=i;}        
	if(k==1){x=n-j-1;y=len;z=i;}
	if(k==2){x=n-1-len;y=n-1-j;z=i;}
	if(k==3){x=j;y=n-1-len;z=i;}
	if(k==4){x=n-i-1;y=j;z=len;}
	if(k==5){x=i;y=j;z=n-1-len;}
}


int main(){
	while(scanf("%d",&n)==1 && n){
		REP(i,n) REP(k,6) REP(j,n) view[k][i][j]=read_char();
		REP(i,n) REP(j,n) REP(k,n) pos[i][j][k]='#';
	
		REP(k,6) REP(i,n) REP(j,n) if(view[k][i][j]=='.')
		REP(p,n) {
			int x,y,z;
			get(k,i,j,p,x,y,z);
			pos[x][y][z]='.';
		}
			
		for(;;){                               //开始删除矛盾小方块 
		 int ok=1;
		 REP(k,6) REP(i,n) REP(j,n){ if(view[k][i][j]!='.'){
		 	REP(p,n){
		 		int x,y,z;
		 		get(k,i,j,p,x,y,z);
		 		if(pos[x][y][z]=='.') continue;
		 		if(pos[x][y][z]=='#'){
				 pos[x][y][z]=view[k][i][j];
				 break;
				}
		 		if(pos[x][y][z]==view[k][i][j]) break;
		 		pos[x][y][z]='.';
		 		ok=0;
			 }
		  }
		}	
		if(ok) break;	
	}
			int ans=0;
			REP(i,n) REP(j,n) REP(k,n)
			if(pos[i][j][k]!='.') ans++;
			printf("Maximum weight: %d gram(s)\n",ans);
}
			return 0;
}

 

发布了57 篇原创文章 · 获赞 58 · 访问量 626

猜你喜欢

转载自blog.csdn.net/weixin_43568895/article/details/103744777