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. ...
随机推荐
- C++简易酒店管理系统,实现(查询、入住、退房、楼层选择、退出)功能
#include <iostream> #include <string.h> #include <stdlib.h> void enter(); void che ...
- Tcl/Cmds
- thinkphp5开发restful-api接口 学习笔记一
视频学习地址: http://study.163.com/course/courseMain.htm?courseId=1004171002 源码和文档(如果满意,欢迎 star): https:// ...
- SolrCloud下DIH实践
创建Collection 在/usr/local/solrcloud/solr/server/solr文件夹下创建coreTest文件夹 将/usr/local/solrcloud/solr/serv ...
- STM32F407VET6之IAR之ewarm7.80.4工程建立(基于官方固件库1.6版本) 的工程文件目录
最后整理结构如下所示,├─cmsis│ startup_stm32f401xx.s│ startup_stm32f40xx.s│ startup_stm32f40_41xxx.s│ startup_s ...
- LOJ 101 最大流(ISAP 模板)
开long long的最大流 #include<bits/stdc++.h> using namespace std; ;//点数的最大值 ;//边数的最大值 ; struct Edge ...
- POJ:2342-Anniversary party(树形dp入门题目)
传送门:http://poj.org/problem?id=2342 Anniversary party Time Limit: 1000MS Memory Limit: 65536K Descrip ...
- django 缓存 实现
由于Django构建得是动态网站,每次客户端请求都要严重依赖数据库,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存,缓存将一个某个views的返回值保存至内存或者memcache中, ...
- JAVA-基础(三)
Character 类型字符(Character)是围绕字符型(char)的一个简单的包装器.字符(Character)的构造函数如下:Character(char ch)这里ch指定了被创建的字符( ...
- ogre3D学习基础9 -- 光源程序实例
这一章练习一下光源的使用,光源分为三种:点光源,聚光源,有向光.具体内容前面说过,这里就不解释了. 继续在上一章的程序的基础上实现. 1.创建摄像机(Camera) createCamera()函数是 ...