Scarlet最近学会了一个数组魔法,她会在n*nn∗n二维数组上将一个奇数阶方阵按照顺时针或者逆时针旋转90°,
首先,Scarlet会把11到n^2n2的正整数按照从左往右,从上至下的顺序填入初始的二维数组中,然后她会施放一些简易的魔法。
Scarlet既不会什么分块特技,也不会什么Splay套Splay,她现在提供给你她的魔法执行顺序,想让你来告诉她魔法按次执行完毕后的二维数组。
输入格式第一行两个整数n,mn,m,表示方阵大小和魔法施放次数。
接下来mm行,每行44个整数x,y,r,zx,y,r,z,表示在这次魔法中,Scarlet会把以第xx行第yy列为中心的2r+12r+1阶矩阵按照某种时针方向旋转,其中z=0z=0表示顺时针,z=1z=1表示逆时针。
输出格式输出nn行,每行nn个用空格隔开的数,表示最终所得的矩阵
输入输出样例输入 #1
5 4 2 2 1 0 3 3 1 1 4 4 1 0 3 3 2 1
输出 #1
5 10 3 18 15 4 19 8 17 20 1 14 23 24 25 6 9 2 7 22 11 12 13 16 21说明/提示
对于50%的数据,满足r=1r=1
对于100%的数据1leq n,mleq5001≤n,m≤500,满足1leq x-rleq x+rleq n,1leq y-rleq y+rleq n1≤x−r≤x+r≤n,1≤y−r≤y+r≤n
以下是AC代码,最后一个可能会超时,多试几次能水过,暂时没有想到好的方法。public class Main {
public static void main(String[] args) {
java.util.Scanner sc = new java.util.Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int arr[][] = new int[n][n];
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
arr[i][j] = ++count;
}
}
for (int i = 0; i < m; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
int r = sc.nextInt();
int z = sc.nextInt();
int res[][] = new int[2 * r + 1][2 * r + 1];
for (int j = x - r - 1, a = 0; j < x + r && a < res.length; j++, a++) {
for (int k = y - r - 1, b = 0; k < y + r && b < res.length; k++, b++) {
res[a][b] = arr[j][k];
}
}
res = tran(z, res);
for (int j = x - 1 - r, a = 0; j < x + r && a < res.length; j++, a++) {
for (int k = y - 1 - r, b = 0; k < y + r && b < res.length; k++, b++) {
arr[j][k] = res[a][b];
}
}
}
for (int o = 0; o < arr.length; o++) {
for (int j = 0; j < arr[0].length; j++) {
System.out.print(arr[o][j] + " ");
}
System.out.println();
}
}
public static int[][] tran(int z, int matrix[][]) {
int[][] temp = new int[matrix[0].length][matrix.length];
int dst = matrix.length - 1;
if (z == 0) {
for (int i = 0; i < matrix.length; i++, dst--) {
for (int j = 0; j < matrix[0].length; j++) {
temp[j][dst] = matrix[i][j];
}
}
} else {
for (int i = 0; i < matrix.length; i++) {
int n = matrix.length - 1;
for (int j = 0; j < matrix[0].length; j++, n--) {
temp[n][i] = matrix[i][j];
}
}
}
return temp;
}
}


![(java版)P4924 [1007]魔法少女小Scarlet ---Java题解 (java版)P4924 [1007]魔法少女小Scarlet ---Java题解](http://www.mshxw.com/aiimages/31/710945.png)
