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  } 
  • 相关阅读:
    微信公众平台开发心得笔记
    MFC中 在线程里获取主对话框上编辑框中的内容
    MFC中 使用Tab Control 控件在对话框中添加属性页
    MFC中 将std::string转换为LPCTSTR的方法
    MFC中 给按钮添加图片的方法
    MFC中 使用多线程实现语音播放功能
    MFC中 Group Box 控件会覆盖掉部分其他控件
    MFC中 CSting与std::string互相转换
    MFC中 给对话框添加背景图片
    MFC中 通过对子对话框的操作来更新主对话框
  • 原文地址:https://www.cnblogs.com/jj81/p/7636885.html
Copyright © 2011-2022 走看看