#牛客创作赏金赛#import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// 构造拉丁方阵
int[][] matrix = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = (i + j) % n + 1;
}
}
// 计算每一行和每一列的异或和
int minThreshold = 0;
for (int i = 0; i < n; i++) {
int rowXor = 0, colXor = 0;
for (int j = 0; j < n; j++) {
rowXor ^= matrix[i][j];
colXor ^= matrix[j][i];
}
minThreshold = Math.max(minThreshold, Math.max(rowXor, colXor));
}
// 输出结果
System.out.println(minThreshold);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
}#ai智能作图#
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// 构造拉丁方阵
int[][] matrix = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = (i + j) % n + 1;
}
}
// 计算每一行和每一列的异或和
int minThreshold = 0;
for (int i = 0; i < n; i++) {
int rowXor = 0, colXor = 0;
for (int j = 0; j < n; j++) {
rowXor ^= matrix[i][j];
colXor ^= matrix[j][i];
}
minThreshold = Math.max(minThreshold, Math.max(rowXor, colXor));
}
// 输出结果
System.out.println(minThreshold);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
}#ai智能作图#
全部评论
相关推荐