2009年4月1日星期三

URAL 1127

小岛叫我做下,说不好做,可惜10分钟就ac了。。。时间空间复杂度都极小。。。至于其中缘由,见下程序。。。。。。。。。
题目大致意思是给你一些相同大小的正方体,每个正方体六个面上涂有不同颜色,选一些正方体堆成一个 1x1xK 的塔,要求前后左右四个面必须分别是一种颜色,问 K 最大为多少。

既然有人问了,就说明下,Q[a, b, c, d] 表示四个面颜色为 a、b、c、d (顺时针或逆时针)时的 K 的最大值。


program ural_1127;
const
 Front = 1;
 Right = 2;
 Left  = 3;
 Rear  = 4;
 Top  = 5;
 Bottom = 6;
var
 Ans, N: Longint;
 i, j, k, l: Longint;
 Q: array [1..10, 1..10, 1..10, 1..10] of Longint;
 D: array [1..6] of Longint;
 C: Char;

begin
 fillchar(Q, sizeof(Q), 0);
 readln(N);
 for i := 1 to N do
  begin
   for j := 1 to 6 do
    begin
     read(C);
     case C of
      'A': D[j] := 1;
      'B': D[j] := 2;
      'C': D[j] := 3;
      'G': D[j] := 4;
      'O': D[j] := 5;
      'R': D[j] := 6;
      'S': D[j] := 7;
      'V': D[j] := 8;
      'W': D[j] := 9;
      'Y': D[j] := 10
     end
    end;
   readln;
   // Front - Right - Rear - Left
   inc(Q[D[Front], D[Right], D[Rear], D[Left]]);
   inc(Q[D[Right], D[Rear], D[Left], D[Front]]);
   inc(Q[D[Left], D[Front], D[Right], D[Rear]]);
   inc(Q[D[Rear], D[Left], D[Front], D[Right]]);
   
   inc(Q[D[Left], D[Rear], D[Right], D[Front]]);
   inc(Q[D[Rear], D[Right], D[Front], D[Left]]);
   inc(Q[D[Right], D[Front], D[Left], D[Rear]]);
   inc(Q[D[Front], D[Left], D[Rear], D[Right]]);
   
   // Front - Top - Rear - Bottom
   inc(Q[D[Front], D[Top], D[Rear], D[Bottom]]);
   inc(Q[D[Top], D[Rear], D[Bottom], D[Front]]);
   inc(Q[D[Bottom], D[Front], D[Top], D[Rear]]);
   inc(Q[D[Rear], D[Bottom], D[Front], D[Top]]);

   inc(Q[D[Bottom], D[Rear], D[Top], D[Front]]);
   inc(Q[D[Rear], D[Top], D[Front], D[Bottom]]);
   inc(Q[D[Top], D[Front], D[Bottom], D[Rear]]);
   inc(Q[D[Front], D[Bottom], D[Rear], D[Top]]);
   
   // Left - Top - Right - Bottom
   inc(Q[D[Left], D[Top], D[Right], D[Bottom]]);
   inc(Q[D[Top], D[Right], D[Bottom], D[Left]]);
   inc(Q[D[Bottom], D[Left], D[Top], D[Right]]);
   inc(Q[D[Right], D[Bottom], D[Left], D[Top]]);

   inc(Q[D[Bottom], D[Right], D[Top], D[Left]]);
   inc(Q[D[Right], D[Top], D[Left], D[Bottom]]);
   inc(Q[D[Top], D[Left], D[Bottom], D[Right]]);
   inc(Q[D[Left], D[Bottom], D[Right], D[Top]])
  end;
 Ans := 0;
 for i := 1 to 10 do
  for j := 1 to 10 do
   for k := 1 to 10 do
    for l := 1 to 10 do
     if Q[i, j, k, l] > Ans then
      Ans := Q[i, j, k, l];
 writeln(Ans)
end.