Secrete Master Plan

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 871    Accepted Submission(s): 523


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 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.

 

Input
The first line of the input gives the number of test cases, T(1T104). T test cases follow. Each test case contains 4 lines. Each line contains two integers ai0 and ai1 ( 1ai0,ai1100). The first two lines stands for the original plan, the 3rd and 4th 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 y 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
 

Source



思路:
这道题的题意就是给你两个2*2矩阵,看他们能不能经过旋转成为相同的模样。旋转的话,因为这四个数的逆时针顺序是固定不变的,只是他们放的位置从1234变成2341变成3412变成4123,可以发现周期是4,每次数增加后超过4了就减4,所以,这里就用%来表示环进行旋转这个操作。

代码:
#include<stdio.h>    
#include<iostream>  
#include<algorithm>  
using namespace std;  
  
int a[10], b[10];  
  
bool check()  
{  
    bool flag=true;
    for (int i = 0; i < 4; i++)  
    {  
		flag=true;
        int j;  
        for (j = 0; j < 4; j++)  
        if (a[(i + j) % 4] != b[j])  
        {
        	flag=false;
        	break;
        }
        if (flag==true)  
            return true;  
    }  
    return false;  
}  
  
int main()  
{  
    int num;  
    while(scanf("%d", &num)!=EOF)
	{
	    for (int x= 1; x <= num; x++)  
	    {  
	        for (int i = 0; i <= 1; i++)  
	            scanf("%d", &a[i]);  
	        for (int i = 3; i >= 2; i--)  
	            scanf("%d", &a[i]);  
	        for (int i = 0; i <= 1; i++)  
	            scanf("%d", &b[i]);  
	        for (int i = 3; i >= 2; i--)  
	            scanf("%d", &b[i]);  
	        printf("Case #%d: ",x);  
	        bool flagg=check();
	        if(flagg==true)printf("%s\n","POSSIBLE");
	        else printf("%s\n","IMPOSSIBLE");
	    }  	
	}  
    return 0;  
}