科大讯飞笔试 9.17 1 1 0.16
1. 100%
public class Main01 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int m = scan.nextInt();
int n = scan.nextInt();
int k = scan.nextInt();
int l = scan.nextInt();
int[][] arr = new int[m][n];
int[][] sub = new int[k][l];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
arr[i][j] = scan.nextInt();
}
}
for (int i = 0; i < k; i++) {
for (int j = 0; j < l; j++) {
sub[i][j] = scan.nextInt();
}
}
int[][] res = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
int sum = 0;
for (int o = -(k / 2); o <= k / 2; o++) {
for (int p = -(l / 2); p <= l / 2; p++) {
int x = i + o;
int y = j + p;
if (x >= 0 && x < m && y >= 0 && y < n){
sum += arr[x][y] * sub[o + k/2][p + l/2];
}
}
}
if (sum > 255) {
sum = 255;
}
if (sum < 0) {
sum = 0;
}
res[i][j] = sum;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(res[i][j]);
if (j != n-1) {
System.out.print(" ");
}
}
System.out.println();
}
}
}
2. 100% 就是力扣上岛屿面积的题
public class Main02 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int m = scan.nextInt();
int n = scan.nextInt();
int[][] before = new int[m][n];
int[][] after = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
before[i][j] = scan.nextInt();
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
after[i][j] = scan.nextInt();
}
}
int res = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (after[i][j] == before[i][j]) {
res = Math.max(res, process(before,after,m,n,i,j));
}
}
}
System.out.println(res);
}
public static int process(int[][] before, int[][] after, int m, int n, int i, int j) {
if (i < 0 || i >= m || j < 0 || j >= n) {
return 0;
}
if (after[i][j] != before[i][j]) {
return 0;
}
after[i][j] = before[i][j]+1;
int a = process(before, after, m, n, i+1, j);
int b = process(before, after, m, n, i-1, j);
int c = process(before, after, m, n, i, j+1);
int d = process(before, after, m, n, i, j-1);
return a+b+c+d+1;
}
} 3. 直接打印4骗分,根本没思路
深信服公司福利 830人发布