zoukankan      html  css  js  c++  java
  • ACM Secrete Master Plan

    Problem Description
    Master Mind KongMing gave Fei Zhang a secrete master plan stashed in a pocket. The plan instructs how to deploy soldiers on the four corners of the city wall. Unfortunately, when Fei opened the pocket he found there are only four numbers written in dots on a piece of sheet. The numbers form 2×2



     
    Input
    The first line of the input gives the number of test cases, T(1T104)Tai0ai11ai0,ai11003rd4th
     
    Output
    For each test case, output one line containing "Case #x: y", where x is the test case number
    (starting from 1) and y
     
    Sample Input
    4
    1 2
    3 4
    1 2
    3 4
     
    1 2
    3 4
    3 1
    4 2
     
    1 2
    3 4
    3 2
    4 1
     
    1 2
    3 4
    4 3
    2 1
     
    Sample Output
    Case #1: POSSIBLE
    Case #2: POSSIBLE
    Case #3: IMPOSSIBLE
    Case #4: POSSIBLE
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 /*
     4     方块旋转,两个矩形,如果能够通过旋转使两个一样则输出 possible
     5      否则则输出impossible 
     6 */
     7 int  A[5][5],B[5][5];  //矩阵A,矩阵B 
     8 //判断现两个矩形是否一样 
     9 bool Judge()       
    10 {
    11     for(int i = 0; i < 2; i++)
    12         for(int j = 0; j < 2; j++)
    13             if(A[i][j] != B[i][j])
    14                 return false;
    15     return true;
    16 }
    17 //将一个矩形进行旋转,顺时针旋转,
    18 //破点:将[0][0]先后进行向左、斜方向、向下交换 
    19 void Swap()
    20 {
    21     swap(A[0][0],A[0][1]);
    22     swap(A[0][0],A[1][1]);
    23     swap(A[0][0],A[1][0]);    
    24 }
    25 //通过旋转四次进行判定是否满足题意 
    26 bool Solve()
    27 {
    28     for(int i = 0; i < 4; i++)
    29     {
    30         if(Judge())
    31             return true;
    32         else
    33             Swap();
    34     }
    35     return false;
    36 }
    37 
    38 int main()
    39 {
    40     int T,n;
    41     while(~scanf("%d",&T))
    42     {
    43         for(int p= 1; p <= T; p++)
    44         {
    45             
    46             scanf("%d %d %d %d",&A[0][0],&A[0][1],&A[1][0],&A[1][1]);
    47             scanf("%d %d %d %d",&B[0][0],&B[0][1],&B[1][0],&B[1][1]);
    48             printf("Case #%d: ",p);
    49             if(Solve())
    50             {
    51                 printf("POSSIBLE
    ");
    52             }
    53             else
    54             {
    55                 printf("IMPOSSIBLE
    ");    
    56             }
    57             
    58             
    59         }
    60     }
    61     return 0;
    62  } 
  • 相关阅读:
    TODO 模板实践
    C++类继承方式及实践
    【转】C++友元
    C++面向对象实践
    数组指针实践
    引用&指针交换函数实践
    左值引用&右值引用实践【TODO】
    const变量的修改实践
    【转】c语言动态与静态分配
    【转】数组指针&指针数组
  • 原文地址:https://www.cnblogs.com/jj81/p/7636885.html
Copyright © 2011-2022 走看看