LA 2995 Image Is Everything
题目链接:
题意:
有一个n∗n∗n个不同颜色的单位正方体(每个单位正方体六个面颜色相同)组成的大正方体,现在其中一些单位正方体已经缺失,给定该大正方体的六视图,求这个物体剩下的最大正方体个数。
分析:
首先我们假设这个大正方体是满的,然后根据六视图找到对应的立方体块的颜色,如果矛盾,说明该立方体块不在大正方体中。
不停的判断,遇到矛盾就删除,直到没有矛盾存在,这样剩下的立方体块就是最大的满足条件的立方体块了。
这里在判断矛盾的时候注意:
- 如果视图为’.’,那么该面下面的所有立方体都要删除。
- 在遍历六视图进行判断的时候,如果该面没有涂上颜色, 那么我们就假设这个面是表面,把他涂上颜色即可。如果该面已涂的颜色和当前六视图对应面的颜色相同,即不存在矛盾,那么继续判断六视图下一个面。否则,存在矛盾,该立方体删除。
代码:
/*************************************************************************
> File Name: la2995.cpp
> Author: jiangyuzhu
> Mail: 834138558@qq.com
> Created Time: Sat 18 Jun 2016 05:10:57 PM CST
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define sa(n) scanf("%d", &(n))
typedef pair<int, int>p;
const int maxn = 10 + 5, mod = 1e9 + 7, oo = 0x3f3f3f3f;
char pic[maxn][maxn][maxn];
char vol[maxn][maxn][maxn];
int n;
void get(int k, int i, int j, int dept, int &x, int &y, int &z)
{
if(k == 0) x = n - 1 - dept, y = j, z = i; // qian
if(k == 1) x = j, y = dept, z = i;//zuo
if(k == 2) x = dept, y = n - 1 - j, z = i;//hou
if(k == 3) x = n - 1 - j, y = n - 1 - dept, z = i;//you
if(k == 4) x = i, y = j, z = dept;//ding
if(k == 5) x = n - 1 - i, y = j, z = n - 1- dept;//di
}
int main (void)
{
while(~scanf("%d", &n) && n){
for(int i = 0; i < n; i++){
for(int k = 0; k < 6; k++){
for(int j = 0; j < n; j++){
char c = getchar();
while(c < 'A'|| c > 'Z'){
if(c == '.') break;
else c = getchar();
}
pic[k][i][j] = c;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int z = 0; z < n; z++){
vol[i][j][z] = '#';
}
}
}
int x, y, z;
for(int k = 0; k < 6; k++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(pic[k][i][j] == '.'){
for(int m = 0; m < n; m++){
get(k, i, j ,m, x, y, z);
vol[x][y][z] = '.';
}
}
}
}
}
bool found = true;
while(found){
found = false;
for(int k = 0; k < 6; k++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(pic[k][i][j] != '.'){
for(int m = 0; m < n; m++){
get(k, i, j, m, x, y, z);
if(vol[x][y][z] == '.') continue;
if(vol[x][y][z] == '#'){
vol[x][y][z] = pic[k][i][j];
break;
}
if(vol[x][y][z] == pic[k][i][j]) break;
vol[x][y][z] = '.';
found = true;
}
}
}
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int m = 0; m < n; m++){
if(vol[i][j][m] != '.') ans++;
}
}
}
printf("Maximum weight: %d gram(s)\n", ans);
}
return 0;
}
这种套路就是,求最大,那我们就先假设是最大的结果,然后不满足就删去,那么剩下的一定是满足的条件中的最大的。。。
LA 2995 Image Is Everything的更多相关文章
- [ACM_模拟][ACM_数学] LA 2995 Image Is Everything [由6个视图计算立方体最大体积]
Description Your new company is building a robot that can hold small lightweight objects. The robo ...
- LA 2995 Image Is Everything 立方体成像 World Final 2004
有一个 n * n * n 的立方体,其中一些单位立方体已经缺失(剩下部分不一定连通).每个单位立方体重 1 克,且被涂上单一的颜色(即 6 个面的一颜色相同).给出前.左.后.右.顶.底 6 个视图 ...
- LA 2995 立方体成像(模拟)
题目链接:https://vjudge.net/problem/UVALive-2995 这道题的主要难点在于三维坐标系的建立,然后在坐标系中进行迭代更新. 注意用宏定义来简化代码. AC代码: #i ...
- AC日记——楼房 codevs 2995
2995 楼房 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 地平线(x轴)上有n个矩(lou ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- 扫描线+堆 codevs 2995 楼房
2995 楼房 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 地平线(x轴)上有n个矩(lou)形(fan ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
随机推荐
- python有三元运算符吗
所属网站分类: python基础 > 语法,变量,运算符 作者:goodbody 链接: http://www.pythonheidong.com/blog/article/12/ 来源:pyt ...
- hessian应用示例
因为公司的项目远程调用采用的是hessian,故抽时间了解了下hessian,自己也写了一个应用实例,以便加深对hessian的理解. Hessian是一个轻量级的remoting onhttp工具, ...
- matplotlib学习记录 二
# 绘制10点到12点的每一分钟气温变化折线图 import random from matplotlib import pyplot as plt # 让matplotlib能够显示中文 plt.r ...
- POJ:1185-炮兵阵地(状压dp入门)
炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组 ...
- 下载linaro android 4.4.2 for panda4460
$ export MANIFEST_REPO=git://android.git.linaro.org/platform/manifest.git$ export MANIFEST_BRANCH=li ...
- 光学字符识别OCR-7语言模型
由于图像质量等原因,性能再好的识别模型,都会有识别错误的可能性,为了减少识别错误率,可以将识别问题跟统计语言模型结合起来,通过动态规划的方法给出最优的识别结果.这是改进OCR识别效果的重要方法之一. ...
- pip安装及使用
1.pip下载安装 1.1 pip下载 # wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5= ...
- linux 基础 软件的安装 *****
一软件的安装 原代码与tarball 源代码---->编译------>可执行文件 查看文件类型 file命令 是否是二进制文件 注意如果文件的可执行权限 .c结尾的源文件- ...
- 以前刷过的数位dp
TOJ1688: Round Numbers Description The cows, as you know, have no fingers or thumbs and thus are una ...
- 【bzoj2111】[ZJOI2010]Perm 排列计数 dp+Lucas定理
题目描述 称一个1,2,...,N的排列P1,P2...,Pn是Mogic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Mogic的,答案可能很 ...