1030 - Image Is Everything (贪心)
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 (贪心)的更多相关文章
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1030: [JSOI2007]文本生成器 [AC自动机 DP]
1030: [JSOI2007]文本生成器 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3953 Solved: 1614[Submit][Stat ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- code vs 1098 均分纸牌(贪心)
1098 均分纸牌 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有 N 堆纸牌 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
随机推荐
- javascript获取CSS3浏览器前缀
var prefix = (function () { var styles = window.getComputedStyle(document.documentElement, ''), pre ...
- GIt/Github常用命令
1)git init:初始化本地仓库 2)创建文件:touch read.txt 3)当操作本地的文件时,使用常用的命令,如(mv,ls..)就可以操作,当操作暂存区的文件时需要在命令前家git,并且 ...
- Shell中逻辑判断
[ 条件1 -a 条件2 ] 当1和2都真时才为真 [ 条件1 -o 条件2 ] 当1和2其中一个为真即为真 [ ! 条件 ] 取反 && 与 ...
- 监听UITabBarItem来拦截是否要跳转
情景是这样的: 我需要在用户点击"我的"的时候, 判断是否已经登录, 如果没有, 就不进入该界面, 而是跳转到用户登录界面, 所以这里我需要进行UITabBarItem点击事件的拦 ...
- 武汉科技大学ACM :1004: 零起点学算法74——Palindromes _easy version
Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”. Input 输入包含多 ...
- UVA 305 Joseph (约瑟夫环 打表)
Joseph The Joseph's problem is notoriously known. For those who are not familiar with the original ...
- Hibernate 缓存机制(转)
一.why(为什么要用Hibernate缓存?) Hibernate是一个持久层框架,经常访问物理数据库. 为了降低应用程序对物理数据源访问的频次,从而提高应用程序的运行性能. 缓存内的数据是对物理数 ...
- ASP.NET常用技术之Cookie
cookie是一小段的文本信息(多数浏览器限制cookie最大字节数为4096字节),在浏览器和服务器之间随用户请求而传递(用户访问网站,没有设置cookie限制范围情况下,无论请求那个页面,浏览器和 ...
- IE的有条件注释详解
IE的有条件注释是一种专有的(因此是非标准的).对常规(X)HTML注释的Miscrosoft扩展.顾名思义,有条件注释使你能够根据条件(比如浏览器版本)显示代码块.尽管是非标准的,但是有条件注释对于 ...
- CSS强制图片大小
相信大家做网页时经常会碰到大分辨率的图片会把表格涨破以致漂亮的网页面目全非,但只要使用以下的CSS语句即可解决. 该CSS的功能是:大于600的图片自动调整为600显示. <style type ...