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;
}

1030 - Image Is Everything (贪心)的更多相关文章

  1. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  2. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. BZOJ 1030: [JSOI2007]文本生成器 [AC自动机 DP]

    1030: [JSOI2007]文本生成器 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3953  Solved: 1614[Submit][Stat ...

  5. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  8. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  9. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

随机推荐

  1. 富文本 Htmll类 html标签

    HTML类可解析的标签 在手机上显示从网络端获取的数据有两种方式,一种是WebView,另一种是TextView,WebView大家都知道,功能强大但不灵活,下面主要说下TextView. 通过查看a ...

  2. 95秀-dialog 进度对话框 实用工具

    工具Util public class DialogUtil {     public static ProgressDialogView progressDialog;     /**      * ...

  3. linux的colrm命令

    http://book.51cto.com/art/201107/277853.htm http://book.51cto.com/art/201107/277854.htm

  4. GDI+基础(3)

    常用图形绘制 <%@ Page ContentType="image/gif" Language="C#" %> <!--ContentTyp ...

  5. Lesson 7: Responsive Typography In Action

    Lesson 7: Responsive Typography In Action 排版一直都是设计和传达的基础.虽然现在的设计和印刷品设计差别很大,但核心原则还是不变的. Article 1: Bo ...

  6. 星座物语APP

    效果图: 这里的后台管理用的是duducat,大家可以去百度看说明.图片,文字都在duducat后台服务器上,可以自己修改的.(PS:图片这里是随便找的) http://www.duducat.com ...

  7. UI基本之UITextField相关方法属性

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(, , , )]; // ...

  8. PHP XML DOM

    PHP XML DOM 内建的 DOM 解析器使在 PHP 中处理 XML 文档成为可能. DOM 是什么? W3C DOM 提供了针对 HTML 和 XML 文档的标准对象集,以及用于访问和操作这些 ...

  9. 微信公众平台开发(一) ——实现URL接入

    一.填写服务器配置 登录微信公众平台,点击开发者中心,点击“修改配置”按钮,填写服务器地址(URL).Token和EncodingAESKey.URL是开发者用来接收微信消息和事件的接口URL.Tok ...

  10. CSS中zoom:1的作用

    兼容IE6.IE7.IE8浏览器,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:触发IE浏览器的haslayout解决ie下的浮动,margin重叠等一些问题.比如,本站使用DIV做一行 ...