天天看點

The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540Secrete Master Plan

Secrete Master Plan

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

Total Submission(s): 429    Accepted Submission(s): 244

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.

The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540Secrete Master Plan

Input The first line of the input gives the number of test cases,  T(1≤T≤104). T test cases follow. Each test case contains 4 lines. Each line contains two integers ai0and ai1 (1≤ai0,ai1≤100). 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 The 2015 China Collegiate Programming Contest   題意:問一個矩陣旋轉之後是否與另一個矩陣相等。 分析:暴力。

1 #include <cstdio>
 2 #include <iostream>
 3 using namespace std;
 4 
 5 const int N = 2;
 6 int A[2][2], B[2][2], T[2][2];
 7 
 8 int main()
 9 {
10     int test;
11     scanf("%d", &test);
12     for(int testnumber = 1; testnumber <= test; testnumber++)
13     {
14         for(int i = 0; i < 2; i++)
15             for(int j = 0; j < 2; j++)
16                 scanf("%d", &A[i][j]);
17         for(int i = 0; i < 2; i++)
18             for(int j = 0; j < 2; j++)
19                 scanf("%d", &B[i][j]);
20         
21         bool flag = 1;
22         for(int k = 0; k < 4; k++)
23         {
24             T[0][0] = B[0][1];
25             T[0][1] = B[1][1];
26             T[1][0] = B[0][0];
27             T[1][1] = B[1][0];
28             
29             for(int i = 0; i < 2; i++)
30                 for(int j = 0; j < 2; j++)
31                     B[i][j] = T[i][j];
32             
33             /*for(int i = 0; i < 2; i++)
34             {
35                 for(int j = 0; j < 2; j++)
36                     printf("%d ", B[i][j]);
37                 printf("\n");
38             }*/
39             
40             bool okay = 0;
41             for(int i = 0; i < 2 && !okay; i++)
42                 for(int j = 0; j < 2; j++)
43                     if(A[i][j] != B[i][j])
44                     {
45                         okay = 1;
46                         break;
47                     }
48             if(!okay)
49             {
50                 flag = 0;
51                 break;
52             }
53         }
54         if(!flag) printf("Case #%d: POSSIBLE\n", testnumber);
55         else printf("Case #%d: IMPOSSIBLE\n", testnumber);
56     }
57     return 0;
58 }      

View Code

轉載于:https://www.cnblogs.com/StupidBoy/p/5063618.html