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 ( 1N
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)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MaxN=10+5;
char g1[MaxN][MaxN],g2[MaxN][MaxN],g3[MaxN][MaxN],g4[MaxN][MaxN],g5[MaxN][MaxN],g6[MaxN][MaxN];
int p1[MaxN][MaxN],p2[MaxN][MaxN],p3[MaxN][MaxN],p4[MaxN][MaxN],p5[MaxN][MaxN],p6[MaxN][MaxN];
int g[MaxN][MaxN][MaxN];
int n; void init();
void work();
bool update_front();
bool update_left();
bool update_back();
bool update_right();
bool update_top();
bool update_bottom(); int main()
{
for(;;)
{
scanf("%d",&n);
if(n==0) break;
init();
work();
}
return 0;
} void init()
{
for(int i=0;i<n;++i)
scanf("%s %s %s %s %s %s",g1[i],g2[i],g3[i],g4[i],g5[i],g6[i]);
} void work()
{
fill(p1[0],p1[n],0);fill(p2[0],p2[n],0);fill(p3[0],p3[n],0);
fill(p4[0],p4[n],0);fill(p5[0],p5[n],0);fill(p6[0],p6[n],0);
fill(g[0][0],g[n][0],-1);
for(;;)
{
bool quit=true;
if(update_front()) quit=false;
if(update_left()) quit=false;
if(update_back()) quit=false;
if(update_right()) quit=false;
if(update_top()) quit=false;
if(update_bottom()) quit=false;
if(quit) break;
}
int ans=n*n*n;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
for(int k=0;k<n;++k)
if(g[i][j][k]==0) --ans;
printf("Maximum weight: %d gram(s)\n",ans);
} bool update_front()
{
bool upd=false;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
{
int &t=p1[i][j];
char ch=g1[i][j];
if(t==n) continue;
int &val=g[n-t-1][j][i];
if(val==0)
{
++t;
upd=true;
}
else if(ch=='.')
{
val=0;
++t;
upd=true;
}
else if(val==-1)
{
val=ch-'A'+1;
upd=true;
}
else if(val!=ch-'A'+1)
{
val=0;
++t;
upd=true;
}
}
return upd;
} bool update_left()
{
bool upd=false;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
{
int &t=p2[i][j];
char ch=g2[i][j];
if(t==n) continue;
int &val=g[j][t][i];
if(val==0)
{
++t;
upd=true;
}
else if(ch=='.')
{
val=0;
++t;
upd=true;
}
else if(val==-1)
{
val=ch-'A'+1;
upd=true;
}
else if(val!=ch-'A'+1)
{
val=0;
++t;
upd=true;
}
}
return upd;
} bool update_back()
{
bool upd=false;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
{
int &t=p3[i][j];
char ch=g3[i][j];
if(t==n) continue;
int &val=g[t][n-j-1][i];
if(val==0)
{
++t;
upd=true;
}
else if(ch=='.')
{
val=0;
++t;
upd=true;
}
else if(val==-1)
{
val=ch-'A'+1;
upd=true;
}
else if(val!=ch-'A'+1)
{
val=0;
++t;
upd=true;
}
}
return upd;
} bool update_right()
{
bool upd=false;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
{
int &t=p4[i][j];
char ch=g4[i][j];
if(t==n) continue;
int &val=g[n-j-1][n-t-1][i];
if(val==0)
{
++t;
upd=true;
}
else if(ch=='.')
{
val=0;
++t;
upd=true;
}
else if(val==-1)
{
val=ch-'A'+1;
upd=true;
}
else if(val!=ch-'A'+1)
{
val=0;
++t;
upd=true;
}
}
return upd;
} bool update_top()
{
bool upd=false;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
{
int &t=p5[i][j];
char ch=g5[i][j];
if(t==n) continue;
int &val=g[i][j][t];
if(val==0)
{
++t;
upd=true;
}
else if(ch=='.')
{
val=0;
++t;
upd=true;
}
else if(val==-1)
{
val=ch-'A'+1;
upd=true;
}
else if(val!=ch-'A'+1)
{
val=0;
++t;
upd=true;
}
}
return upd;
} bool update_bottom()
{
bool upd=false;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
{
int &t=p6[i][j];
char ch=g6[i][j];
if(t==n) continue;
int &val=g[n-i-1][j][n-t-1];
if(val==0)
{
++t;
upd=true;
}
else if(ch=='.')
{
val=0;
++t;
upd=true;
}
else if(val==-1)
{
val=ch-'A'+1;
upd=true;
}
else if(val!=ch-'A'+1)
{
val=0;
++t;
upd=true;
}
}
return upd;
}
1030 - Image Is Everything的更多相关文章
- BZOJ 1030: [JSOI2007]文本生成器 [AC自动机 DP]
1030: [JSOI2007]文本生成器 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3953 Solved: 1614[Submit][Stat ...
- PAT A 1030. Travel Plan (30)【最短路径】
https://www.patest.cn/contests/pat-a-practise/1030 找最短路,如果有多条找最小消耗的,相当于找两次最短路,可以直接dfs,数据小不会超时. #incl ...
- Light OJ 1030 - Discovering Gold(概率dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...
- Mysql: ERROR 1030 (HY000): Got error 28 from storage engine
今天帮同事解决一个问题的时候,遇到了下面的异常: ERROR 1030 (HY000): Got error 28 from storage engine 我们的数据库是mysql,我们的sql语句是 ...
- loj 1030概率dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 思路:一直以来对这种概率题都挺感冒的=.=......还是说一下思路吧,dp[i ...
- PAT乙级 1030. 完美数列(25)
1030. 完美数列(25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 给定一个正整数数列,和正整数p,设这 ...
- mysql 1030 Got error 28 from storage engine
mysql 1030 Got error 28 from storage engine 错误原因:磁盘临时空间不够. 解决办法:df -h 查看设备存储的使用情况 du -h --max-depth= ...
- hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏
problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...
- 【BZOJ】【1030】【JSOI2007】文本生成器
AC自动机/DP Orz ZYF 玛雅快要省选了,赶紧复(xue)习(xi)一下AC自动机…… 其实在AC自动机上DP并没有当初想的那么复杂……就是把DP的转移关系换成了AC自动机上的边而已(不过这题 ...
- PAT-乙级-1030. 完美数列(25)
1030. 完美数列(25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 给定一个正整数数列,和正整数p,设这 ...
随机推荐
- 第一节 UPC 码
UPC码(Universal Product Code)是最早大规模应用的条码,其特性是一种长度固定.连续性的条码,目前主要在美国和加拿大使用,由於其应用范围广泛,故又被称万用条码. UPC码仅可用来 ...
- 依赖和用jar包得区别
有个项目,需要用到第三方开发的一个jar文件,我先是把生成的jar文件直接拷贝到我的项目的libs目录下,项目自动加载了引用的jar包,在java文件中使用也没有问题,但是由于引用的jar文件中有自定 ...
- 深入探究VC —— 资源编译器rc.exe(3)
Windows应用程序中,图标.菜单.畏途.图标.工具条.对话框等是以资源的形式存在的.开发人员也可以自定义资源类型.如果一个程序使用了资源,那么它在构建时需要对资源进行编译.程序所使用的资源会在资源 ...
- BZOJ 1756: Vijos1083 小白逛公园
题目 1756: Vijos1083 小白逛公园 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 856 Solved: 264[Submit][Sta ...
- NAT简单介绍
NAT本质就是让一群机器公用同一个IP.还有一个重要的用途是保护NAT内的主机不受外界攻击 NAT类型: 1.Full Cone:IPport不受限 Full Cone仅仅做单纯的地址转换,不正确进出 ...
- 扩展欧几里德算法解二元一次方程之B - 青蛙的约会
Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事 ...
- CodeForces 546D Soldier and Number Game 打表(求质因子个数)
题目:戳我这个题与HDUOJ 5317有异曲同工之妙 题意:题意看懂了上面的一大串英文之后其实很简单,就是给你一个正整数n,问你n有多少个质因子,不过这里n是通过a!/b!给定的,也就是说n=(a!/ ...
- c语言求最大公约数和最小公倍数
求最大公约数和最小公倍数 假设有两个数a和b,求a,b的最大公约数和最小公倍数实际上是一个问题,得出这两个数的最大公约数就可以算出它们的最小公倍数. 最小公倍数的公式是 a*b/m m为最大公约数 因 ...
- html向servlet传乱码解决办法
html 设置为utf-8格式 <meta http-equiv="content-type" content="text/html;charset=UTF-8&q ...
- Delphi_MemoryModule — load DLL from memory. Also includes hooking utilities.
https://github.com/Fr0sT-Brutal/Delphi_MemoryModule