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

时间:2021-02-06 19:17:39

有一个 n * n * n 的立方体,其中一些单位立方体已经缺失(剩下部分不一定连通)。每个单位立方体重 1 克,且被涂上单一的颜色(即 6 个面的一颜色相同)。给出前、左、后、右、顶、底 6 个视图,你的任务是判断这个屋里剩下的最大的重量。

看完这题之后,我满头雾水,不知道从何下手。后来模拟了一下数据,才知道怎么解决。

首先,一个单位立方体只有一种颜色,如果从不同的视图看到这个立方体的颜色不同,那么就删除这个立方体。通过这样循环删除,到最后所有的小立方体都符合题目所要求,就是最大的立方体数目,即最大的重量。

附AC代码:

   1: #include <stdio.h>

   2: #include <math.h>

   3: #include <iostream>

   4: #include <cstdarg>

   5: #include <algorithm>

   6: #include <string.h>

   7: #include <stdlib.h>

   8: #include <string>

   9: #include <list>

  10: #include <vector>

  11: #include <map>

  12: #define LL long long

  13: #define M(a) memset(a, 0, sizeof(a))

  14: #define orz(i, k) for(int i = 0; i < k; i++)

  15: using namespace std;

  16:     int n;

  17: void Clean(int count, ...)

  18: {

  19:     va_list arg_ptr;

  20:     va_start (arg_ptr, count);

  21:     for (int i = 0; i < count; i++)

  22:         M(va_arg(arg_ptr, int*));

  23:     va_end(arg_ptr);

  24: }

  25: char Input()

  26: {

  27:     char ch;

  28:     while (1)

  29:     {

  30:         ch = getchar();

  31:         if (ch >= 'A' && ch <= 'Z') return ch;

  32:         else if (ch == '.') return ch;

  33:     }

  34: }

  35:  

  36: void Get(int k, int i, int j, int len, int &x, int &y, int &z)

  37: {

  38:     switch (k)

  39:     {

  40:         case 0: x = len, y = j, z = i; break;

  41:         case 1: x = n - 1 - j, y = len, z = i; break;

  42:         case 2: x = n - 1 - len, y = n - 1 - j, z = i; break;

  43:         case 3: x = j, y = n - 1 - len, z = i; break;

  44:         case 4: x = n - 1 - i, y = j, z = len; break;

  45:         case 5: x = i, y = j, z = n - 1 - len; break;

  46:     }

  47: }

  48:  

  49: char pos[10][10][10];

  50: char view[6][10][10];

  51: int main()

  52: {

  53:     while (~scanf("%d", &n) && n)

  54:     {

  55:         Clean(1, view);

  56:  

  57:         orz(i, n) orz(j, 6) orz(k, n) view[j][i][k] = Input();

  58:         orz(i, n) orz(j, n) orz(k, n) pos[i][j][k] = '#';

  59:         orz(k, 6) orz(i, n) orz(j, n)

  60:         {

  61:             if (view[k][i][j] == '.')

  62:             {

  63:                 orz(l, n)

  64:                 {

  65:                     int x, y, z;

  66:                     Get(k, i, j, l, x, y, z);

  67:                     pos[x][y][z] = '.';

  68:                 }

  69:             }

  70:         }

  71:         while (1)

  72:         {

  73:             bool done = true;

  74:             orz(k, 6) orz(i, n) orz(j, n)

  75:             {

  76:                 orz(l, n)

  77:                 {

  78:                     int x, y, z;

  79:                     Get(k, i, j, l, x, y, z);

  80:                     if (pos[x][y][z] == '.') continue;

  81:                     else if (pos[x][y][z] == '#')

  82:                     {

  83:                         pos[x][y][z] = view[k][i][j];

  84:                         break;

  85:                     }

  86:                     if (pos[x][y][z] == view[k][i][j]) break;

  87:                     pos[x][y][z] = '.';

  88:                     done = false;

  89:                 }

  90:             }

  91:             if (done == true) break;

  92:         }

  93:         int res = 0;

  94:         orz(i, n) orz(j, n) orz(k, n)

  95:             if (pos[i][j][k] != '.') res += 1;

  96:         printf("Maximum weight: %d gram(s)\n", res);

  97:     }

  98:     return 0;

  99: }

(P. S:弄出来之后感觉好有成就感Orz)