1. 程式人生 > >ACM Secrete Master Plan

ACM Secrete Master Plan

分享 fort idt possible rtu 判斷 contain ase ott

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\n"); 52 } 53 else 54 { 55 printf("IMPOSSIBLE\n"); 56 } 57 58 59 } 60 } 61 return 0; 62 }

ACM Secrete Master Plan