矩阵
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem Description
X终于开始玩一些比较高大上的东西了,比如矩阵。给出两个N*N的矩阵A,B。他想知道矩阵A在顺时针旋转一定角度后是否会和矩阵B完全一样。
Input
有多组输入。
每组输入先输入一个整数N(N <= 50),代表矩阵的大小。
接下来的N行,每行有N个整数。代表矩阵A。
再接下来的N行N个整数代表矩阵B。
Output
如果矩阵A在旋转一定角度后能和矩阵B完全一样则输出YES,否则输出NO。
Sample Input
2 1 2 3 4 3 1 4 2 2 1 2 3 4 4 2 3 1
Sample Output
YES NO
Hint
Source
zmx
package leslie1;
//import java.io.*;
//import java.math.*;
//import java.text.*;
//import java.math.BigInteger;
import java.util.*;
public class Main {
static int a[][] = new int[55][55];
static int b[][] = new int[55][55];
static int c[][] = new int[55][55];
static int d[][] = new int[55][55];
static int e[][] = new int[55][55];
static int n = 0;
public static int judge(int x[][]) {
int flag = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
if (b[i][j] != x[i][j])
flag = 0;
}
return flag;
}
public static void init(int a[][],int b[][]) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
a[i][j] = b[n - j + 1][i];
}
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
n = cin.nextInt();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
a[i][j] = cin.nextInt();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
b[i][j] = cin.nextInt();
init(c,a);
init(d,c);
init(e,d);
if (judge(c) == 1 || judge(d) == 1 || judge(e) == 1 || judge(a) == 1)
System.out.println("YES");
else
System.out.println("NO");
}
cin.close();
}
}