【蓝桥杯】第十六届Java B组竞赛解题实录

题目A:高塔脱险

高塔题目示意图

基础难度题目,主要考察基本编程能力,但需特别注意数值范围问题,使用int类型可能导致数据溢出
正确答案:202

package competition.t1;
import java.io.*;
public class Solution {
static class FastIO {
static InputStreamReader reader = new InputStreamReader(System.in);
static StreamTokenizer tokenizer = new StreamTokenizer(reader);
static BufferedReader buffer = new BufferedReader(reader);
static PrintWriter writer = new PrintWriter(System.out);
static int getInt() throws IOException {
tokenizer.nextToken();
return (int) tokenizer.nval;
}
}
public static void main(String[] args) {
long target = 2025;
long result = 0;
for (long i = 1; i

题目本质是寻找满足特定条件的最小N值。设两个日期为a和b,需满足:
(N + a)能被b整除
(N + b)能被a整除
虽然可以考虑中国剩余定理,但实际可通过枚举法解决
转换思路:若(N+a)是b的倍数,则可表示为N = k*b - a
通过求解k值即可推导出最终结果
答案:409876661809331

package competition.t2;
import java.io.*;
public class Solution {
static class FastIO {
// 输入输出工具类同上
}
public static void main(String[] args) {
long date1 = 20250412, date2 = 20240413;
boolean found = false;
for (int i = 9999; i

位运算异或操作解析:将数字转为二进制后,按位比较,相同为0,不同为1
解题思路有两种:
1. 统计每位1的个数,若所有位都是偶数则满足条件
2. 更简便的方法:若两组异或结果相同,则再次异或必为0
因此只需验证最终异或结果是否为0即可

public class Solution {
static class FastIO {
// 输入输出工具类同上
}
public static void main(String[] args) throws IOException {
int testCases = FastIO.getInt();
while (testCases-- > 0) {
int count = FastIO.getInt();
int xorResult = 0;
for (int i = 1; i

题目要求计算a数组和b数组元素两两组合,其和为质数且不超过n+m的组合数量
关键点在于高效质数判断,直接暴力检测会超时
解决方案:使用埃拉托斯特尼筛法预处理质数表

public class Solution {
static class FastIO {
// 输入输出工具类同上
}
static Set primeCache = new TreeSet<>();
static {
// 预处理质数表
int maxNum = 400000;
boolean[] isPrime = new boolean[maxNum + 1];
Arrays.fill(isPrime, true);
for (int i = 2; i  resultSet = new HashSet<>();
for (int i = 0; i  total) break;
if (primeCache.contains(sum)) {
resultSet.add(sum);
}
}
}
FastIO.writer.print(resultSet.size());
FastIO.writer.flush();
}
}
}

题目E:爆破装置

爆破题目示意图

题目转化为图论问题:将所有圆形装置连接成最小生成树
解题步骤:
1. 若两圆相交,边权为0
2. 若不相交,边权为圆心距减去两圆半径
3. 应用Kruskal或Prim算法求解

public class Solution {
static class FastIO {
// 输入输出工具类同上
}
static class Circle {
int id;
int x;
int y;
int radius;
public Circle(int id, int x, int y, int radius) {
this.id = id;
this.x = x;
this.y = y;
this.radius = radius;
}
}
static class Connection implements Comparable {
int from;
int to;
double cost;
public Connection(int from, int to, double cost) {
this.from = from;
this.to = to;
this.cost = cost;
}
@Override
public int compareTo(Connection other) {
return Double.compare(this.cost, other.cost);
}
}
static int[] parent;
static int findRoot(int x) {
return parent[x] == x ? x : (parent[x] = findRoot(parent[x]));
}
public static void main(String[] args) throws IOException {
int n = FastIO.getInt();
parent = new int[n + 1];
for (int i = 1; i

(注:此处省略部分题目解析,保持原文核心内容但采用不同表达方式)

题目H:研发资源调配

资源分配题目示意图

采用直接模拟的方法解决该问题

文章整理自互联网,只做测试使用。发布者:Lomu,转转请注明出处:https://www.it1024doc.com/9364.html

(0)
LomuLomu
上一篇 2025 年 5 月 13 日 上午4:19
下一篇 2025 年 5 月 13 日 上午5:00

相关推荐

  • ChatGPT Plus自己账号国内充值教程

    ChatGPT Plus 适合长期使用,但前提是会员开在自己的账号里。国内用户只要把支付和账号确认流程理顺,后续续费和继续使用都会更简单。如果你只是想快速完成会员升级,可以重点看卡密验证和账号确认两部分。

    未分类 2026 年 7 月 24 日
    7100
  • 库存系统:仓库层、调度层、销售层的库存数据模型设计

    大家好,我是汤师爷~ 让我们一起深入挖掘库存概念模型的设计精髓,这不仅是构建库存管理系统的基石,更是确保库存数据精准和一致性的核心所在。 库存的数据模型设计 下图展示了库存概念模型的设计概览。通过精心设计的概念模型,我们能够有效支撑库存管理的多元化业务需求。 仓库层 仓库层是商品库存存放和管理的实际场所,承担着具体的仓储操作任务。它涵盖了企业自建仓库、第三方…

    2024 年 12 月 24 日
    73700
  • SuperGrok订阅无需国外信用卡教程

    SuperGrok订阅无需国外信用卡教程,适合国内用户使用微信支付宝为自己的账号完成充值、订阅或代充开通。

    未分类 2026 年 7 月 28 日
    9500
  • 什么是南北向流量和东西向流量?

    在现代云计算和微服务架构中,南北向流量与东西向流量是两种至关重要的网络流量模式。 南北向流量(North-South Traffic) 定义:南北向流量指的是穿越系统边界的流量,通常是从外部环境进入系统内部或从系统内部向外传输的数据流,例如用户通过浏览器或移动应用访问Web服务或API。 特点:这种流量模式涉及跨越网络边界的通信,如从外部网络进入内部网络,或…

    未分类 2024 年 12 月 24 日
    77100
  • ChatGPT充值官方支付失败替代方案

    ChatGPT充值官方支付失败替代方案,适合已经放弃绑卡尝试的人,重点说明微信支付宝、账号核对和会员到账状态。

    未分类 2026 年 5 月 20 日
    20200

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信