• 第十五届蓝桥杯模拟赛【第三期】Java


    1.

    package 第十五届模拟赛;
    
    public class problem01 {
        public static void main(String[] args) {
            int ans = 0;
            for (int i = 1; i <= 2023; ++i) {
                if (2023 % i == 0) {
                    ans++;
                    System.out.println(i);
                }
            }
            System.out.println(ans);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    2.

    package 第十五届模拟赛;
    
    public class problem02 {
        public static void main(String[] args) {
            int ans = 0;
            for (int i = 10; i <= 100; ++i) {
                for (int j = 0; j <= 100; ++j) {
                    if (i - j >= 10) {
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    3.

    package 第十五届模拟赛;
    
    public class problem03 {
        static final int N = 1000000;
        static int[] p = new int[N + 10];
        static boolean[] vis = new boolean[N + 10];
        static int cnt = 0;
        static void isP() {
            for (int i = 2; i * i <= N; ++i) {
                for (int j = i * i; j <= N; j += i) {
                    vis[j] = true;
                }
            }
        }
        public static void main(String[] args) {
            isP();
            int ans = 0;
            for (int i = 2; i <= N; ++i) {
                if (!vis[i] && check(i)) {
                    ans++;
                    //System.out.println(i);
                }
            }
            System.out.println(ans);
        }
        static boolean check(int n) {
            int res = 0;
            while(n > 0) {
                res += n % 10;
                n /= 10;
            }
            return res == 23;
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    4.

    package 第十五届模拟赛;
    
    import java.math.BigInteger;
    
    public class problem04 {
        public static void main(String[] args) {
            BigInteger a = new BigInteger("12345678901234567890123456789012345678901234567890");
            BigInteger b = new BigInteger("2023");
            BigInteger mod = a.mod(b);
            System.out.println(mod);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    5.

    package 第十五届模拟赛;
    
    import java.util.Scanner;
    
    public class problem05 {
        static int[][] mp = new int[30][20];
        public static void main(String[] args) {
            int n, m;
            n = 30; m = 20;
            Scanner scanner = new Scanner(System.in);
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    mp[i][j] = scanner.nextInt();
                }
            }
            int ans = 0;
            int c = 5, d = 5;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (i + c > n || j + d > m) {
                        continue;
                    }
                    int tmp = 0;
                    for (int x = i; x < i + c; ++x) {
                        for (int y = j; y < j + d; ++y) {
                            tmp += mp[x][y];
                        }
                    }
                    ans = Math.max(ans, tmp);
                }
            }
            System.out.println(ans);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    6.

    package 第十五届模拟赛;
    
    import java.util.*;
    
    /**
     * 小蓝要上一个楼梯,楼梯共有 n 级台阶(即小蓝总共要走 n 级)。小蓝每一步可以走 1 级、2 级或 3 级台阶。
     *   请问小蓝至少要多少步才能上到楼梯顶端?
     * 输入格式
     *   输入一行包含一个整数 n 。
     * 输出格式
     *   输出一行包含一个整数,表示答案。
     */
    public class problem06 {
        static final int N = 10000 + 10;
        static int[] f = new int[N];
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            f[1] = f[2] = f[3] = 1;
            for (int i = 4; i <= n; ++i) {
                f[i] = min(f[i - 1], f[i - 2], f[i - 3]) + 1;
            }
            System.out.println(f[n]);
        }
        static int min(int a, int b, int c) {
            int t = Math.min(a, b);
            return Math.min(t, c);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    7.

    package 第十五届模拟赛;
    
    import java.util.Scanner;
    
    public class problem07 {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            String s = scanner.next();
            int ans = 0;
            for (int i = 0; i < s.length(); ++i) {
                if ((s.charAt(i) - '0') % 2 == 1) {
                    ans++;
                }
            }
            System.out.println(ans);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    8.

    package 第十五届模拟赛;
    
    import java.util.Scanner;
    
    public class problem08 {
        static final int N = 1000 + 10;
        static int[] a = new int[N];
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            for (int i = 0; i < n; ++i) {
                a[i] = scanner.nextInt();
            }
            int mx = Integer.MIN_VALUE, mi = Integer.MAX_VALUE;
            for (int i = 1; i < n - 1; ++i) {
                if (a[i] < a[i - 1] && a[i] < a[i + 1]) {
                    mx = Math.max(mx, a[i]);
                }
                if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
                    mi = Math.min(mi, a[i]);
                }
            }
            System.out.println(mx + " " + mi);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    9.

    package 第十五届模拟赛;
    
    
    import java.util.Scanner;
    
    public class problem09 {
        static final int N = 1000 + 10;
        static char[][] mp = new char[N][N];
        static int[][] dir = {{1, 0}, {-1, -1}, {-1, 1}};
        static int n, m;
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            n = scanner.nextInt(); m = scanner.nextInt();
            for (int i = 0; i < n; ++i) {
                mp[i] = scanner.next().toCharArray();
            }
            int ans = 0;
            int[][] a = new int[3][3];
            for (int i = 1; i < n; i++) {
                for (int j = 1; j < m; j++) {
                    int cur_x = i, cur_y = j, cur_v = mp[i][j], tmp = 0;
                    for (int k = 0; k < 3; ++k) { // 三个方向初始化
                        a[k][0] = dir[k][0] + i;
                        a[k][1] = dir[k][1] + j;
                        if (!check(a[k][0], a[k][1])) {
                            break;
                        }
                        a[k][2] = mp[a[k][0]][a[k][1]];
                    }
                    while(check(a[0][0], a[0][1]) && check(a[1][0], a[1][1]) && check(a[2][0], a[2][1])
                            && mp[a[0][0]][a[0][1]] == mp[i][j] &&  mp[a[1][0]][a[1][1]] == mp[i][j] &&  mp[a[2][0]][a[2][1]] == mp[i][j]) { // 三个坐标在范围内,并且三个值相同
                        tmp++;
                        for (int k = 0; k < 3; ++k) { // 三个方向初始化
                            a[k][0] = dir[k][0] + a[k][0];
                            a[k][1] = dir[k][1] + a[k][1];
                            if (!check(a[k][0], a[k][1])) {
                                break;
                            }
                            a[k][2] = mp[a[k][0]][a[k][1]];
                        }
                    }
                    ans = Math.max(ans, tmp);
                }
            }
            System.out.println(ans);
        }
        static boolean check(int x, int y) {
            return !(x < 0 || y < 0 || x >= n || y >= m);
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52

    10.

    package 第十五届模拟赛;
    
    import java.util.Scanner;
    
    public class problem10 {
        static final int N = 1000000 + 10;
        static final int MOD = 1000000007;
        static int[] f = new int[N];
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            f[a] = f[b] = f[c] = 1;
            // a + b
            for (int i = a + 1; i <= n; ++i) {
                f[i] = (f[i] + f[i - a]) % MOD;
                if (i >= b) {
                    f[i] = (f[i] + f[i - b]) % MOD;
                }
                if (i >= c) {
                    f[i] = (f[i] + f[i - c]) % MOD;
                }
            }
            System.out.println(f[n] % MOD);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
  • 相关阅读:
    新时代布局新特性 -- 容器查询
    Nginx快速上手
    合肥工业大学计算机网络实验一
    详细的科技特长生路径和成长规划
    子组件自定义事件$emit实现新页面弹窗关闭之后父界面刷新
    数据结构(13)最小生成树JAVA版:prim算法、kruskal算法
    DeepRT论文笔记
    2022/08/26 day11:高级数据类型
    PyTorch - 模型训练损失 (Loss) NaN 问题的解决方案
    【Java+SpringBoot】外卖点餐系统
  • 原文地址:https://blog.csdn.net/qq_45249273/article/details/136608114