题目链接:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996

题意:

有一个n∗n∗n个不同颜色的单位正方体(每个单位正方体六个面颜色相同)组成的大正方体,现在其中一些单位正方体已经缺失,给定该大正方体的六视图,求这个物体剩下的最大正方体个数。

分析:

首先我们假设这个大正方体是满的,然后根据六视图找到对应的立方体块的颜色,如果矛盾,说明该立方体块不在大正方体中。

不停的判断,遇到矛盾就删除,直到没有矛盾存在,这样剩下的立方体块就是最大的满足条件的立方体块了。

这里在判断矛盾的时候注意:

  1. 如果视图为’.’,那么该面下面的所有立方体都要删除。
  2. 在遍历六视图进行判断的时候,如果该面没有涂上颜色, 那么我们就假设这个面是表面,把他涂上颜色即可。如果该面已涂的颜色和当前六视图对应面的颜色相同,即不存在矛盾,那么继续判断六视图下一个面。否则,存在矛盾,该立方体删除。

代码:

  1. /*************************************************************************
  2. > File Name: la2995.cpp
  3. > Author: jiangyuzhu
  4. > Mail: 834138558@qq.com
  5. > Created Time: Sat 18 Jun 2016 05:10:57 PM CST
  6. ************************************************************************/
  7. #include<iostream>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<cmath>
  11. #include<queue>
  12. #include<stack>
  13. using namespace std;
  14. #define sa(n) scanf("%d", &(n))
  15. typedef pair<int, int>p;
  16. const int maxn = 10 + 5, mod = 1e9 + 7, oo = 0x3f3f3f3f;
  17. char pic[maxn][maxn][maxn];
  18. char vol[maxn][maxn][maxn];
  19. int n;
  20. void get(int k, int i, int j, int dept, int &x, int &y, int &z)
  21. {
  22. if(k == 0) x = n - 1 - dept, y = j, z = i; // qian
  23. if(k == 1) x = j, y = dept, z = i;//zuo
  24. if(k == 2) x = dept, y = n - 1 - j, z = i;//hou
  25. if(k == 3) x = n - 1 - j, y = n - 1 - dept, z = i;//you
  26. if(k == 4) x = i, y = j, z = dept;//ding
  27. if(k == 5) x = n - 1 - i, y = j, z = n - 1- dept;//di
  28. }
  29. int main (void)
  30. {
  31. while(~scanf("%d", &n) && n){
  32. for(int i = 0; i < n; i++){
  33. for(int k = 0; k < 6; k++){
  34. for(int j = 0; j < n; j++){
  35. char c = getchar();
  36. while(c < 'A'|| c > 'Z'){
  37. if(c == '.') break;
  38. else c = getchar();
  39. }
  40. pic[k][i][j] = c;
  41. }
  42. }
  43. }
  44. for(int i = 0; i < n; i++){
  45. for(int j = 0; j < n; j++){
  46. for(int z = 0; z < n; z++){
  47. vol[i][j][z] = '#';
  48. }
  49. }
  50. }
  51. int x, y, z;
  52. for(int k = 0; k < 6; k++){
  53. for(int i = 0; i < n; i++){
  54. for(int j = 0; j < n; j++){
  55. if(pic[k][i][j] == '.'){
  56. for(int m = 0; m < n; m++){
  57. get(k, i, j ,m, x, y, z);
  58. vol[x][y][z] = '.';
  59. }
  60. }
  61. }
  62. }
  63. }
  64. bool found = true;
  65. while(found){
  66. found = false;
  67. for(int k = 0; k < 6; k++){
  68. for(int i = 0; i < n; i++){
  69. for(int j = 0; j < n; j++){
  70. if(pic[k][i][j] != '.'){
  71. for(int m = 0; m < n; m++){
  72. get(k, i, j, m, x, y, z);
  73. if(vol[x][y][z] == '.') continue;
  74. if(vol[x][y][z] == '#'){
  75. vol[x][y][z] = pic[k][i][j];
  76. break;
  77. }
  78. if(vol[x][y][z] == pic[k][i][j]) break;
  79. vol[x][y][z] = '.';
  80. found = true;
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. int ans = 0;
  88. for(int i = 0; i < n; i++){
  89. for(int j = 0; j < n; j++){
  90. for(int m = 0; m < n; m++){
  91. if(vol[i][j][m] != '.') ans++;
  92. }
  93. }
  94. }
  95. printf("Maximum weight: %d gram(s)\n", ans);
  96. }
  97. return 0;
  98. }

这种套路就是,求最大,那我们就先假设是最大的结果,然后不满足就删去,那么剩下的一定是满足的条件中的最大的。。。

LA 2995 Image Is Everything的更多相关文章

  1. [ACM_模拟][ACM_数学] LA 2995 Image Is Everything [由6个视图计算立方体最大体积]

    Description   Your new company is building a robot that can hold small lightweight objects. The robo ...

  2. LA 2995 Image Is Everything 立方体成像 World Final 2004

    有一个 n * n * n 的立方体,其中一些单位立方体已经缺失(剩下部分不一定连通).每个单位立方体重 1 克,且被涂上单一的颜色(即 6 个面的一颜色相同).给出前.左.后.右.顶.底 6 个视图 ...

  3. LA 2995 立方体成像(模拟)

    题目链接:https://vjudge.net/problem/UVALive-2995 这道题的主要难点在于三维坐标系的建立,然后在坐标系中进行迭代更新. 注意用宏定义来简化代码. AC代码: #i ...

  4. AC日记——楼房 codevs 2995

    2995 楼房  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 地平线(x轴)上有n个矩(lou ...

  5. 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 ...

  6. 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 ...

  7. 扫描线+堆 codevs 2995 楼房

    2995 楼房  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 地平线(x轴)上有n个矩(lou)形(fan ...

  8. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  9. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

随机推荐

  1. python有三元运算符吗

    所属网站分类: python基础 > 语法,变量,运算符 作者:goodbody 链接: http://www.pythonheidong.com/blog/article/12/ 来源:pyt ...

  2. hessian应用示例

    因为公司的项目远程调用采用的是hessian,故抽时间了解了下hessian,自己也写了一个应用实例,以便加深对hessian的理解. Hessian是一个轻量级的remoting onhttp工具, ...

  3. matplotlib学习记录 二

    # 绘制10点到12点的每一分钟气温变化折线图 import random from matplotlib import pyplot as plt # 让matplotlib能够显示中文 plt.r ...

  4. POJ:1185-炮兵阵地(状压dp入门)

    炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组 ...

  5. 下载linaro android 4.4.2 for panda4460

    $ export MANIFEST_REPO=git://android.git.linaro.org/platform/manifest.git$ export MANIFEST_BRANCH=li ...

  6. 光学字符识别OCR-7语言模型

    由于图像质量等原因,性能再好的识别模型,都会有识别错误的可能性,为了减少识别错误率,可以将识别问题跟统计语言模型结合起来,通过动态规划的方法给出最优的识别结果.这是改进OCR识别效果的重要方法之一. ...

  7. pip安装及使用

    1.pip下载安装 1.1 pip下载 # wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5= ...

  8. linux 基础 软件的安装 *****

    一软件的安装   原代码与tarball 源代码---->编译------>可执行文件 查看文件类型   file命令    是否是二进制文件 注意如果文件的可执行权限 .c结尾的源文件- ...

  9. 以前刷过的数位dp

    TOJ1688: Round Numbers Description The cows, as you know, have no fingers or thumbs and thus are una ...

  10. 【bzoj2111】[ZJOI2010]Perm 排列计数 dp+Lucas定理

    题目描述 称一个1,2,...,N的排列P1,P2...,Pn是Mogic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Mogic的,答案可能很 ...