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 (   1N10 ). 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)

题意:给定立方体的几个视图的颜色。 '.'代表能看穿,求立方体最多几块。

思路:有'.'的那一行肯定能穿过去。但是还不够,如果两个方向看过去的颜色不一样。当前那块肯定要删掉。按照这样删到不能删为止。就是最重的。

代码:

#include <stdio.h>
#include <string.h>
const int N = 10;
int n, x, y, z;
char view[N][6][N], res[N][N][N]; void tra(int i, int j, int k, int l) {
if (j == 0) {x = i; y = k; z = l;}
if (j == 1) {x = i, y = l; z = n - 1 - k;}
if (j == 2) {x = i; y = n - 1 - k; z = n - 1 - l;}
if (j == 3) {x = i; y = n - 1 - l; z = k;}
if (j == 4) {x = l; y = k; z = n - 1 - i;}
if (j == 5) {x = n - 1 - l; y = k; z = i;}
} void init() {
for (int i = 0; i < n; i ++)
for (int j = 0; j < n; j ++)
for (int k = 0; k < n; k ++)
res[i][j][k] = '#';
for (int i = 0; i < n; i ++)
for (int j = 0; j < 6; j ++) {
for (int k = 0; k < n; k ++) {
scanf("%c", &view[i][j][k]);
if (view[i][j][k] == '.') {
for (int l = 0; l < n; l ++) {
tra(i, j, k, l);
res[x][y][z] = '.';
}
}
}
getchar();
}
} int solve() {
while (1) {
int flag = true;
for (int i = 0; i < n; i ++)
for (int j = 0; j < 6; j ++)
for (int k = 0; k < n; k ++) {
if (view[i][j][k] != '.') {
for (int l = 0; l < n; l ++) {
tra(i, j, k, l);
if (res[x][y][z] == '.') continue;
if (res[x][y][z] == '#')
res[x][y][z] = view[i][j][k];
if (res[x][y][z] == view[i][j][k]) break;
res[x][y][z] = '.';
flag = false;
}
}
}
if (flag) break;
}
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 (res[i][j][k] != '.')
ans ++;
return ans; } int main() {
while (~scanf("%d%*c", &n) && n) {
init();
printf("Maximum weight: %d gram(s)\n", solve());
}
return 0;
}

最新文章

  1. Android Sqlite基本命令
  2. 【转】SVN管理多个项目版本库
  3. ECSHOP修改后台地址
  4. iOS后台运行
  5. google域名邮箱申请 gmail域名邮箱申请(企业应用套件)指南
  6. vs2012如何创建报表
  7. HDU4627+LCM
  8. Uva 11889 Benefit (lcm与gcd)
  9. JMeter基础教程2:正则表达式使用
  10. 洛谷P3369 【模板】普通平衡树(Treap/SBT)
  11. vue前端开发。。。
  12. C语言博客作业04--数组
  13. SPFA找最大比例环
  14. Mysql数据库账户权限设置
  15. python3 十六进制字符串进行分割并累加
  16. OpenCV相机标定坐标系详解
  17. Python 高级编程——单例模式
  18. Climbing Stairs - LeetCode
  19. 关于ueditor与arcgis js api同用会报错的问题
  20. Django HttpRequest对象详解

热门文章

  1. codevs 2800 送外卖(状压dp)
  2. 以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。
  3. sql设置事务隔离级别
  4. Android Translate 动画跳跃和缓慢移动
  5. PHP编程规范
  6. xib添加手势后报错:-[UITapGestureRecognizer setFrame:]: unrecognized selector sent to instance xxx
  7. C# linq的学习及使用
  8. java 代码第一天练习
  9. 在Mvc中创建WebApi是所遇到的问题
  10. java Socket 长连接 心跳包 客户端 信息收发 demo