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

1.

java 复制代码
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);
    }
}

2.

java 复制代码
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);
    }
}

3.

java 复制代码
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;
    }
}

4.

java 复制代码
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);
    }
}

5.

java 复制代码
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);
    }
}

6.

java 复制代码
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);
    }
}

7.

java 复制代码
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);
    }
}

8.

java 复制代码
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);
    }
}

9.

java 复制代码
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);
    }

}

10.

java 复制代码
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);
    }
}
相关推荐
P.H. Infinity11 分钟前
【RabbitMQ】04-发送者可靠性
java·rabbitmq·java-rabbitmq
生命几十年3万天15 分钟前
java的threadlocal为何内存泄漏
java
caridle27 分钟前
教程:使用 InterBase Express 访问数据库(五):TIBTransaction
java·数据库·express
^velpro^32 分钟前
数据库连接池的创建
java·开发语言·数据库
苹果醋335 分钟前
Java8->Java19的初步探索
java·运维·spring boot·mysql·nginx
秋の花40 分钟前
【JAVA基础】Java集合基础
java·开发语言·windows
小松学前端43 分钟前
第六章 7.0 LinkList
java·开发语言·网络
Wx-bishekaifayuan1 小时前
django电商易购系统-计算机设计毕业源码61059
java·spring boot·spring·spring cloud·django·sqlite·guava
customer081 小时前
【开源免费】基于SpringBoot+Vue.JS周边产品销售网站(JAVA毕业设计)
java·vue.js·spring boot·后端·spring cloud·java-ee·开源
全栈开发圈1 小时前
新书速览|Java网络爬虫精解与实践
java·开发语言·爬虫