#UVa:253-Cube painting

灆洢 2012-10-20 23:53:50

要檢驗兩個正方體的塗色是否相同,就檢查兩個正方體的三組對面(1-6,2-5,3-4)是否能夠根據交換順序(每一組對面內的兩個顏色可互換,三組對面的順序可交換)來達成相同的結果,即可得解。

C++(0.008)

/*******************************************************/
/* UVa 253 Cube painting                               */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2012/10/20                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  string input;
  string cube[2];
  bool used[3];
  while( getline( cin, input ) ){
    cube[0] = input.substr( 0, 6 );
    cube[1] = input.substr( 6, 6 );

    fill( used, used+3, false ); 
    for( int i = 0 ; i < 3 ; i++ ){
      for( int j = 0 ; j < 3 ; j++ ){
        if( !used[j] && 
            ((cube[1][j] == cube[0][i] && cube[1][5-j] == cube[0][5-i]) ||
              cube[1][5-j] == cube[0][i] && cube[1][j] == cube[0][5-i]) ){
          used[j] = true;
          break;
        }
      }
    }

    if( used[0] && used[1] && used[2] ) printf( "TRUE\n" );
    else printf( "FALSE\n" );
  }
  return 0;
}

在〈“#UVa:253-Cube painting”〉中有 2 則留言

  1. anonymous表示:

    For case like rgbrgbrgrbgb (123456 and 124356) correct answer should be FALSE, as reflection must be used to put them the same, but your code generates TRUE.

    • In your case, we can rotate these cubes with the axis through the g-g face to put them as the same, so it is TRUE.
      And in the statement about the input of the problem, it said "(Reflections are not allowed.)".

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料