科大讯飞笔试 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骗分,根本没思路

#23届秋招笔面经#
全部评论
最后一题就六个案例,其中四个是4,17,20,26,我就生成一个随机数,每次从里面随机选一个,跑了差不多十几次,过了50%
点赞 回复 分享
发布于 2022-09-17 22:38 江苏
不是,我想问一下楼主,我c++和你java一样的代码,N^4,为什么你的可以100%?我的不行
点赞 回复 分享
发布于 2022-09-18 07:40 安徽

相关推荐

评论
3
9
分享

创作者周榜

更多
牛客网
牛客企业服务