【第22期】观点:IT 行业加班,到底有没有价值?

uva 1030 - Image Is Everything(迭代更新)

原创 2013年12月02日 21:15:04

题目链接:uva 1030 - Image Is Everything


题目大意:有一个最大为n*n*n的立方体的一个不规整立体,由若干个1*1*1的小正方体构成(每一个小正方体被涂成不同的颜色),给出n,然后是该立体的前、左、后、右、上和下的视图,然后判断该立体的最大体积是多少。


解题思路:首先先把所有视图上为‘.'的地方清空,然后枚举视图上不为’.'的地方,计算对应的坐标第一个不为空得位置,将其涂色(注意,若一个正方体被着两种不同的颜色,说明该位置不存在正方体)。


#include <stdio.h>
#include <string.h>

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

int n;
char view[N][N][N], pos[N][N][N];

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

void input() {
	REP(i, n) REP(k, 6) REP(j, n) view[k][i][j] = getChar();
	REP(x, n) REP(y, n) REP(z, n) pos[x][y][z] = '#';
}

void search(int i, int j, int k, int p, int& x, int& y, int& z) {
	switch(k) {
		case 0:
			x = i, y = j, z = p; return;
		case 1:
			x = i, y = p, z = n - j - 1; return;
		case 2:
			x = i, y = n - j - 1, z = n - p - 1; return;
		case 3:
			x = i, y = n - p - 1, z = j; return;
		case 4:
			x = p, y = j, z = n - i - 1; return;
		case 5:
			x = n - p - 1, y = j, z = i; return;
	}
}

int solve() {

	int x, y, z;

	REP(k, 6) REP(i, n) REP(j, n)
		if (view[k][i][j] == '.')
			REP(p, n) {
				search(i, j, k, p, x, y, z);
				pos[x][y][z] = '.';
			}

	while (true) {
		bool flag = true;
		REP(k, 6) REP(i, n) REP(j, n)
			if (view[k][i][j] != '.')
				REP(p, n) {
					search(i, j, k, p, x, y, z);
					if (pos[x][y][z] == '.') continue;
					if (pos[x][y][z] == '#')
						pos[x][y][z] = view[k][i][j];

					if(pos[x][y][z] == view[k][i][j]) break;
					pos[x][y][z] = '.';
					flag = false;
				}
		if (flag) break;
	}

	int ans = 0;
	REP(x, n) REP(y, n) REP(z, n)
		if (pos[x][y][z] != '.') ans++;
	return ans;
}

int main () {
	while (scanf("%d", &n) == 1 && n) {
		input();
		printf("Maximum weight: %d gram(s)\n", solve() );
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

World Finals 2004 / UVa 1030 Image Is Everything (想法题&迭代更新)

1030 - Image Is Everything Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com...

Everything Is an Object(Thinking In Java读书笔记)

  <span style="font-size: 13pt; font-family: Tahoma; color: #000000; font-weight: normal; font-s

程序员升职加薪指南!还缺一个“证”!

CSDN出品,立即查看!

UVA 1030 - Image Is Everything(贪心枚举)

Description Your new company is building a robot that can hold small lightweight objects. The rob...

函数、匿名-Scala 学习笔记(二)— Everything is an object -by小雨

新手发帖,不太懂规矩,有错误的地方请大家见谅,欢迎批评指正     Everything is an object     媒介     Scala is a <spa...

UVa 529 - Addition Chains ,迭代加深搜索+减枝

题目链接: UVA :http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)