Secrete Master Plan(HDU - 5540)

Secrete Master Plan(HDU - 5540)

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×22×2 matrix, but Fei didn't know the correct direction to hold the sheet. What a pity! 

Given two secrete master plans. The first one is the master's original plan. The second one is the plan opened by Fei. As KongMing had many pockets to hand out, he might give Fei the wrong pocket. Determine if Fei receives the right pocket. 
Secrete Master Plan(HDU - 5540) 

Input

The first line of the input gives the number of test cases, T(1≤T≤104)T(1≤T≤104). TT test cases follow. Each test case contains 4 lines. Each line contains two integers ai0ai0and ai1ai1 (1≤ai0,ai1≤1001≤ai0,ai1≤100). The first two lines stands for the original plan, the 3rd3rdand 4th4th line stands for the plan Fei opened.

Output

For each test case, output one line containing " Case #x: y", where x is the test case number 
(starting from 1) and yy is either "POSSIBLE" or "IMPOSSIBLE" (quotes for clarity).

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

题目翻译:

孔明师父把藏在口袋里的秘密计划交给张飞。该计划指导如何在城墙的四角部署士兵。不幸的是,当费先生打开口袋时,他发现一张纸上只有四个用点写的数字。这些数字构成了2×2矩阵,但费不知道拿纸的正确方向。真遗憾!

有两个秘密的总体计划。第一个是大师最初的计划。第二个是费先生开启的计划。孔明有很多口袋要分发,他可能给错了费的口袋。确定飞是否收到了正确的口袋。

输入

输入的第一行给出测试用例的数量,T(1≤T≤104)。接下来是T测试用例。每个测试用例包含4行。每一行包含两个整数ai0和ai1(1≤ai0,ai1≤100)。前两行代表原计划,第三行和第四行代表菲开的计划。

输出

对于每个测试用例,输出一行包含“case #x: y”,其中x是测试用例号

(从1开始),y是“可能的”或者“不可能的”。

思路:判断张飞打开的2X2矩阵是不是能通过旋转变成诸葛亮交给他的原矩阵。

AC代码:

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <math.h>
using namespace std;
int a[5][5];
int b[5][5];
int temp[5][5];
int main()
{
    int t;
    scanf("%d",&t);
    int k=1;
    while(t--)
    {
        for(int i=1; i<=2; i++)
            for(int j=1; j<=2; j++)
                scanf("%d",&a[i][j]);
        for(int i=1; i<=2; i++)
            for(int j=1; j<=2; j++)
                scanf("%d",&b[i][j]);
        int flag=0;
        for(int u=1; u<=4; u++)
        {
            temp[1][1]=b[1][2];
            temp[1][2]=b[2][2];
            temp[2][1]=b[1][1];
            temp[2][2]=b[2][1];
            temp[2][2]=b[2][1];
            int tmp=1;
            for(int x=1; x<=2; x++)
            {
                for(int y=1; y<=2; y++)
                {
                    if(a[x][y]!=temp[x][y])
                    {
                        tmp=0;
                        break;
                    }
                }
                if(!tmp)
                    break;
            }
            flag=tmp;
            if(flag)
                break;
            for(int i=1; i<=2; i++)
                for(int j=1; j<=2; j++)
                    b[i][j]=temp[i][j];
        }
        printf("Case #%d: ",k++);
        if(flag)
            printf("POSSIBLE\n");
        else
            printf("IMPOSSIBLE\n");
    }
    return 0;
}