HDOJ 5540 Secrete Master Plan(qwb铜牌题 用%进行环的旋转)

来源:互联网 发布:淘宝客批量申请定向 编辑:程序博客网 时间:2024/05/16 10:28

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 integersai0 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
41 23 41 23 41 23 43 14 21 23 43 24 11 23 44 32 1
 

Sample Output
Case #1: POSSIBLECase #2: POSSIBLECase #3: IMPOSSIBLECase #4: POSSIBLE
 

Source
The 2015 China Collegiate Programming Contest 



思路:
这道题的题意就是给你两个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;  }  


0 0
原创粉丝点击