导航菜单
首页 >  蓝桥杯软件类真题  > 2023年第十四届蓝桥杯JavaB组省赛真题(题目+全部完整题解)

2023年第十四届蓝桥杯JavaB组省赛真题(题目+全部完整题解)

目录

A、阶乘求和

 Ⅰ、题目解读

Ⅱ、代码 

B、幸运数字

 Ⅰ、题目解读

 Ⅱ、代码

C: 数组分割(时间限制: 1.0s 内存限制: 512.0MB)

 Ⅰ、解题思路

 Ⅱ、代码

 D、矩形总面积(时间限制: 1.0s 内存限制: 512.0MB)

 Ⅰ、题目解读

Ⅱ、代码 

 E、蜗牛(时间限制: 1.0s 内存限制: 512.0MB)

 Ⅰ、题目解读

 Ⅱ、代码

 F、合并区域 (时间限制: 2.0s 内存限制: 512.0MB)

 Ⅰ、题目解读

 Ⅱ、代码

 G、买二赠一(时间限制: 1.0s 内存限制: 512.0MB)

 Ⅰ、题目解读

 Ⅱ、代码1(复杂度过大,超时)

代码2(正确答案)

 H、合并石子(时间限制: 1.0s 内存限制: 512.0MB)

 Ⅰ、题目解读

Ⅱ、代码

 I、最大开支(时间限制: 1.0s 内存限制: 512.0MB )

 Ⅰ、题目解读

 J、魔法阵(时间限制: 1.0s 内存限制: 512.0MB )

 总结

2023年第十四届蓝桥杯JavaB组省赛文件已上传到csdn,可自行下载

蓝桥杯题目:2023年第十四届蓝桥杯大赛软件类省赛Java大学B组真题 - 题库 - C语言网 (dotcpp.com)

详细完整题解在这篇博客:

2023年第十四届蓝桥杯省赛JavaB组个人题解(AK)_迷你滨的博客-CSDN博客

A、阶乘求和【问题描述】令S= 1! + 2! + 3! +...+ 202320232023!,求S的末尾9位数字。提示:答案首位不为0。  Ⅰ、题目解读

 一看到三个2023的巨大数字,我想大家应该都人都麻了。但是我想说这是官方的骗术,因为题目说要求末尾的9位数,其实我想告诉大家当加到40多的阶乘时,这个阶乘和后面的9位数就不会发生改变了。

Ⅱ、代码  public class Main {public static void main(String[] args) {long start=1;String s="202320232023";long end= Long.parseLong(s);long sum=0;long cj=1;while (start40)System.out.println(sum);}System.out.println(sum);}}

 看运行

20940313420940313420940313420940313420940313420940313420940313...

这是因为40的阶乘之后后面 9位数都是0,所以阶乘之和末尾9位数不会再发生改变!

B、幸运数字【问题描述】哈沙德数是指在某个固定的进位制当中,可以被各位数字之和整除的正整 数。例如 126是十进制下的一个哈沙德数,因为(126)10mod(1+2+6) = 0;126 也是八进制下的哈沙德数,因为 (126)10= (176)8,(126)10mod(1 + 7 + 6) = 0; 同时 126也是16进制下的哈沙德数,因为(126)10= (7e)16,(126)10mod(7 +e) = 0。小蓝认为,如果一个整数在二进制、八进制、十进制、十六进制下均为 哈沙德数,那么这个数字就是幸运数字,第 1至第10个幸运数字的十进制表示 为:1,2,4,6,8,40,48,72,120,126. . .。现在他想知道第2023个幸运数 字是多少?你只需要告诉小蓝这个整数的十进制表示即可。  Ⅰ、题目解读

 这题就是考察大家的进制转换,数据量也不大。直接看代码吧!

 Ⅱ、代码 public class {public static void main(String[] args) {int j=0;for (int i=1;i 0){int n = scan.nextInt();int[] a = new int[n];long x = 0, y = 0; // x 记录偶数, y 记录奇数for(int i = 0; i < n; i++){a[i] = scan.nextInt() % 2;if(a[i] == 0){x++;}else {y++;}}if(y % 2 == 1){ // 奇数个数为奇,没有一个条件成立System.out.println(0);continue;}x = x + (y == 0 ? 0 : y - 1); // 两个奇数组合为一个偶数,排除重复情况BigInteger ans = new BigInteger("2");BigInteger dp = new BigInteger("1");// C(n,m) = P(n,m) / P(m,m) = n! / m! * (n - m)!// 转移递推公式 dp = (dp * (x, x-1, x-2, ... , n) / (1, 2, 3, ... , n))for(long i = 1, j = x; i < x; i++, j--){ // 排列组合无顺序 CBigInteger u = new BigInteger(String.valueOf(j));BigInteger v = new BigInteger(String.valueOf(i));dp = dp.multiply(u).divide(v);ans = ans.add(dp);}System.out.println(ans.mod(MOD));}}}

  优化高精度

import java.util.Scanner;import java.math.BigInteger;public class Main {public static final BigInteger MOD = new BigInteger("1000000007");public static final BigInteger TWO = new BigInteger("2");public static void main(String[] args) {Scanner scan = new Scanner(System.in);int T = scan.nextInt();while (T-- > 0) {int n = scan.nextInt();int x = 0, y = 0; // x 记录偶数, y 记录奇数for (int i = 0; i < n; i++) {int a = scan.nextInt() % 2;if (a == 0) {x++;} else {y++;}}if (y % 2 == 1) {System.out.println(0);}else{System.out.println(TWO.pow(x + (y == 0 ? 0 : y - 1)).mod(MOD));}}}}  D、矩形总面积(时间限制: 1.0s 内存限制: 512.0MB)【问题描述】平面上有个两个矩形R1和R2,它们各边都与坐标轴平行。设(x1,y1)和 (x2,y2)依次是R1的左下角和右上角坐标,(x3,y3)和(x4,y4)依次是R2的左下 角和右上角坐标,请你计算 R1和R2的总面积是多少?注意:如果R1和R2有重叠区域,重叠区域的面积只计算一次。 【输入格式】输入只有一行,包含8个整数,依次是:x1,y1,x2,y2,x3,y3,x4和y4。 【输出格式】一个整数,代表答案。 【样例输入】2 1 7 4 5 3 8 6【样例输出】 22 【样例说明】 样例中的两个矩形如图所示:

【评测用例规模与约定】 对于 20 % 的数据, R 1 和 R 2 没有重叠区域。 对于 20 % 的数据,其中一个矩形完全在另一个矩形内部。 对于 50 % 的数据,所有坐标的取值范围是 [0 , 10³  ] 。 对于 100 % 的数据,所有坐标的取值范围是 [0 , 10⁵  ]  Ⅰ、题目解读

这题有两种解法,自己数组去求,但是可能数据量过大会爆栈。第二种就是公式直接求解,这时求两个矩形相交的面积改怎么求?

矩形相交要使条件成立,即min(x2,x4)-max(x1,x3)>=0 且min(y2,y4)-max(y1,y3)>=0 如果条件成立,则相交矩形面积为:(min(x2,x4)-max(x1,x3))* (min(y2,y4)-max(y1,y3))

Ⅱ、代码  import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int x1 = sc.nextInt();int y1 = sc.nextInt();int x2 = sc.nextInt();int y2 = sc.nextInt();int x3 = sc.nextInt();int y3 = sc.nextInt();int x4 = sc.nextInt();int y4 = sc.nextInt();long area1 = (long) (x2 - x1) * (y2 - y1); // 计算第一个矩形的面积long area2 = (long) (x4 - x3) * (y4 - y3); // 计算第二个矩形的面积long overlapArea=0;long l = Math.min(x2, x4) - Math.max(x1, x3);long w= Math.min(y2,y4)-Math.max(y1,y3);if (l >=0&&w >=0){overlapArea= l * w;}long Area = area1 + area2 - overlapArea; // 总面积System.out.println(Area); // 输出总面积}}  E、蜗牛(时间限制: 1.0s 内存限制: 512.0MB)【问题描述】这天,一只蜗牛来到了二维坐标系的原点。 在 x轴上长有n根竹竿。它们平行于y轴,底部纵坐标为0,横坐标分别 为 x1,x2, ...,xn。竹竿的高度均为无限高,宽度可忽略。蜗牛想要从原点走到第n个竹竿的底部也就是坐标(xn,0)。它只能在x轴上或者竹竿上爬行,在x轴上爬行速度为1单位每秒;由于受到引力影响,蜗牛在竹竿上向上和向下爬行 的速度分别为 0.7单位每秒和1.3单位每秒。 为了快速到达目的地,它施展了魔法,在第 i和i+ 1根竹竿之间建立了传 送门(0 【样例输出】

4.20 【样例说明】 蜗牛路线: (0 , 0) → (1 , 0) → (1 , 1) → (10 , 1) → (10 , 0) → (11 , 0) ,花费时间为 1 +1/  0.7 + 0 + 1/1 .3 + 1 ≈ 4 . 20 【评测用例规模与约定】 对于 20 % 的数据,保证 n ≤ 15 ; 对于 100 % 的数据,保证 n ≤ 10⁵ ,a i , b i ≤ 10⁴ ,x i ≤ 10⁹ 。 Ⅰ、题目解读

dp[i][j] 表示蜗牛走到第 i 根杆子的最短用时,j 表示状态。 j = 0 : 走到杆子底部 j = 1 :走到杆子的传送门处 P.S.由于只与前一个杆子状态有关,其实用两个变量就行,用二维数组便于理解 时间复杂度: O(n)

 Ⅱ、代码 import java.io.*;import java.util.*;public class Main{static int maxn = 200005,n,m;static long INF = (long)2e18,ans = 0,mod = (int)1e9+7;static Scanner sc = new Scanner (System.in);static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));static StreamTokenizer st =new StreamTokenizer(bf);static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));public static void main(String[]args) throws IOException{int T = 1;//T = Integer.parseInt(S());while(T-->0) solve();pw.flush();}static final int I() throws IOException {st.nextToken();return (int)st.nval;}static void solve() throws IOException{n = I();long x[] = new long [n+1];for(int i=1;i

相关推荐: