Image Is Everything UVALive - 2995 World Finals 2004

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)


给定一个 N * N * N 的立方体,部分块缺失,现给出6个面所观察到的状态,求问最多有多少个小立方体(总体积);

getpos 表示 在第k个面中,第 i 行 j 列,深度为 len 时,该木块所在的 (x,y,z)坐标;
参考 lrj 的代码实现;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 300005
#define inf 0x3f3f3f3f
#define INF 2147480000
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)

inline int rd() {
	int x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }

int n;
char pos[20][20][20];
char vw[6][20][20];

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

void getPos(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 - 1 - j, y = len, z = i;
	if (k == 2)x = n - 1 - len, z = i, y = n - 1 - j;
	if (k == 3)x = j, y = n - 1 - len, z = i;
	if (k == 4)x = n - 1 - i, y = j, z = len;
	if (k == 5)x = i, y = j, z = n - 1 - len;
}

int main()
{
	//ios::sync_with_stdio(false);
	while (cin >> n && n) {
		REP(i, n) REP(k, 6) REP(j, n)vw[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 (vw[k][i][j] == '.') {
			REP(len, n) {
				int x, y, z; getPos(k, i, j, len, x, y, z);
				pos[x][y][z] = '.';
			}
		}
		while (1) {
			bool fg = true;
			REP(k, 6) REP(i, n) REP(j, n) if (vw[k][i][j] != '.') {
				REP(p, n) {
					int x, y, z; getPos(k, i, j, p, x, y, z);
					if (pos[x][y][z] == '.')continue;
					if (pos[x][y][z] == '#') {
						pos[x][y][z] = vw[k][i][j]; break;
					}
					if (pos[x][y][z] == vw[k][i][j])break;
				//	pos[x][y][z] = '.'; 
					fg = false;
				}
			}
			if (fg)break;
		}
		int tot = 0;
		REP(i, n)
			REP(j, n) REP(k, n) if (pos[i][j][k] != '.')tot++;
		printf("Maximum weight: %d gram(s)\n", tot);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40273481/article/details/83040199