行业知识
【蓝桥真题】——2023年蓝桥Java组省赛真题+解析+代码(通俗易懂版)
【蓝桥真题】——2023年蓝桥Java组省赛真题+解析+代码(通俗易懂版)
大家好,我是爱刷题的小贾,欢迎交流指正~
全网最详细蓝桥杯真题+解析+代码,绝对通俗易懂,一点就通!
专治各种没资源,没思路,没代码等新手入门级BUG
全文目录
试题 A: 阶乘求和⭐
1 代码:
2 题目分析:
试题 B: 幸运数字⭐
1 代码:
2 题目分析:
试题 D: 矩形总面积⭐⭐
1 代码:
2 题目分析:
试题 G: 买二赠一⭐⭐
1 代码:
2 题目分析:
试题 H: 合并石子⭐⭐⭐
1 代码:
2题目思路:
说在最后
说在前面
关于这次蓝桥杯,比赛的时候没有看D题,G和H花了好长时间,呜呜…,等比赛结束的时候边走边看题才知道是送分题,考后相当于是补题了,好遗憾,痛失10分,也许人生就是这样,十之八九是遗憾,但这又有何妨呢,前方康庄大道,还有很多美好的事情等着我呢!!!
下面就把这次我看过的并且感觉能做的题目写一下吧,如有错误,欢迎评论区指正!!
试题 A: 阶乘求和
【问题描述】
令 S = 1! + 2! + 3! + … + 202320232023! ,求 S 的末尾 9 位数字。
提示:答案首位不为 0 。
【答案提交】
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一
个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
代码:
/** * @author jqx * @date 2023-04-08 9:11 */public class t1 { public static void main(String[] args) {// 420940313 long ans=0; long temp=1000000000; long temp1=1; for (long i = 1; i temp1=((temp1%temp)*(i%temp))%temp; ans=(ans%temp+temp1%temp)%temp; System.out.println("temp1是:"+temp1+" ans是:"+ans+" i是:"+i); }// System.out.println("答案是:"+ans); }} public static void main(String[] args) { int ans=0; int i=0; while (true){ i++; if(isCheck(i)){ ans++; System.out.println(i+"为第"+ans+"个"); } if(ans==2023){ break; } } System.out.println("答案是:"+i); } static boolean isCheck(int n){ String temp1=Integer.toString(n,2); String temp2=Integer.toString(n,8); String temp3=n+""; String temp4=Integer.toString(n,16); int temp_1=0; int temp_2=0; int temp_3=0; int temp_4=0; for (int i = 0; i 题目分析:
答案是:215040
1.直接把数先进制转换,然后求数位和,判读能否整除数位和就好了
2.这题本质考一个进制转换,如果会用Java的API就很简单,前两天我在算法组会分享的时候刚好讲过,还写了题解,还上了热榜,下面链接的第五题
蓝桥杯最后一战_小羊不会飞的博客-CSDN博客分巧克力_二分题目描述输入格式输出格式输入输出样例说明/提示代码:巧克力 - 优先队列题目描述输入格式输出格式输入输出样例说明/提示代码:思路分析:秘密行动_dp蓝桥杯算法提高-秘密行动题目描述输入格式输出格式样例输入样例输出代码:思路分析:合并果子_优先队列题目描述输入格式输出格式输入输出样例说明/提示代码:思路分析:回文平方数_进制转换API题目描述输入格式输出格式https://blog.csdn.net/m0_55858611/article/details/129960460?spm=1001.2014.3001.5501
试题 D: 矩形总面积
【问题描述】
平面上有个两个矩形 R 1 和 R 2 ,它们各边都与坐标轴平行。设 ( x 1 , y 1 ) 和( x 2 , y 2 ) 依次是 R 1 的左下角和右上角坐标, ( x 3 , y 3 ) 和 ( x 4 , y 4 ) 依次是 R 2 的左下角和右上角坐标,请你计算 R 1 和 R 2 的总面积是多少?注意:如果 R 1 和 R 2 有重叠区域,重叠区域的面积只计算一次。
【输入格式】
输入只有一行,包含 8 个整数,依次是: x 1 , y 1 , x 2 , y 2 , x 3, y 3 , x 4 和 y 4 。
【输出格式】
一个整数,代表答案。
【样例输入】
2 1 7 4 5 3 8 6
【样例输出】
22
【样例说明】
样例中的两个矩形如图所示:
【评测用例规模与约定】
对于 20 % 的数据, R 1 和 R 2 没有重叠区域。
对于 20 % 的数据,其中一个矩形完全在另一个矩形内部。
对于 50 % 的数据,所有坐标的取值范围是 [0 , 10 ^3 ] 。
对于 100 % 的数据,所有坐标的取值范围是 [0 , 10^ 5 ] 。
代码:
/** * @author jqx * @date 2023-04-08 9:11 */import java.io.*;/** 1. @author yx 2. @date 2023-04-08 13:57 */public class D { static PrintWriter out =new PrintWriter(System.out); static BufferedReader ins=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer in=new StreamTokenizer(ins); public static void main(String[] args) throws IOException { String[] sp=ins.readLine().split(" "); int x1=Integer.parseInt(sp[0]); int y1=Integer.parseInt(sp[1]); int x2=Integer.parseInt(sp[2]); int y2=Integer.parseInt(sp[3]); int x3=Integer.parseInt(sp[4]); int y3=Integer.parseInt(sp[5]); int x4=Integer.parseInt(sp[6]); int y4=Integer.parseInt(sp[7]); long ans=0; int max_X=Math.max(Math.max(x1,x2),Math.max(x3,x4)); int max_Y=Math.max(Math.max(y1,y2),Math.max(y3,y4)); int max=Math.max(max_X,max_Y); int[][] Map=new int[max+1][max+1]; for (int i = y1; i for (int j = x1; j Map[i][j]+=1; } } for (int i = y3; i for (int j = x3; j Map[i][j]+=1; } } for (int i = 0; i for (int j = 0; j // System.out.print(Map[j][i]+" "); if(Map[j][i]=1){ ans++; } }// System.out.println(); } System.out.println(ans); }} static PrintWriter out = new PrintWriter(System.out); static BufferedReader ins = new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer in = new StreamTokenizer(ins); public static void main(String[] args) throws IOException { String s = ins.readLine(); int N = Integer.parseInt(s); String[] sp = ins.readLine().split(" "); ArrayList list.add(Integer.parseInt(sp[i])); } Collections.sort(list); for (int i = 0; list.size()0 ; i++) { int a1 = 0; int a2 = 0; a1 = list.get(list.size() - 1); list.remove(list.size() - 1); if(list.size() - 1=0) { a2 = list.get(list.size() - 1); list.remove(list.size() - 1); int mid = a2 / 2; int length=list.size(); for (int j = length-1; j = 0; j--) { if (list.get(j) list.remove(j); break; } } } ans += (a1 + a2); } out.println(ans); out.flush(); }} static class Node implements Comparable int count; int color; Node(int count, int color) { this.count = count; this.color = color; } @Override public int compareTo(Node o) { if(this.color==o.color){ return this.count-o.count; }else { return 0; } } } static PrintWriter out = new PrintWriter(System.out); static BufferedReader ins = new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer in = new StreamTokenizer(ins); public static void main(String[] args) throws IOException { String s = ins.readLine(); int n = Integer.parseInt(s); String[] strings1 = ins.readLine().split(" "); String[] strings2 = ins.readLine().split(" "); Node[] nodes = new Node[n]; int count = 0; int color = 0; long ans=0; ArrayList count = Integer.parseInt(strings1[i]); color = Integer.parseInt(strings2[i]); Node node = new Node(count, color); list.add(node); } Collections.sort(list);// for (int i = 0; i 堆号变为1…)蓝桥杯最后一战_小羊不会飞的博客-CSDN博客分巧克力_二分题目描述输入格式输出格式输入输出样例说明/提示代码:巧克力 - 优先队列题目描述输入格式输出格式输入输出样例说明/提示代码:思路分析:秘密行动_dp蓝桥杯算法提高-秘密行动题目描述输入格式输出格式样例输入样例输出代码:思路分析:合并果子_优先队列题目描述输入格式输出格式输入输出样例说明/提示代码:思路分析:回文平方数_进制转换API题目描述输入格式输出格式https://blog.csdn.net/m0_55858611/article/details/129960460?spm=1001.2014.3001.5501
1.这题我用局部优先队列的思想,用ArrayList实现,自定义一个Node,然后重写排序,局部堆号相同的按堆数count递增排序(count小的先合,并保证count数大的堆重复合并次数最少)
2.从头节点开始往下遍历,判断下一个堆是否能合并,如果能合并,更新当前节点,删除下一个节点,ans+=当前节点的count+下一个节点的count
3.最后list的节点个数就是最小堆数
说在最后
趁着刚比完赛,思路还是比价清晰的,终于写完了题解,相比去年我感觉自己面对算法变得更加从容了一些(虽然还是算法小菜鸡),这段时间因为要备战考研,所以每天也就只能在上课的时候练算法题,考研之余写写算法有时会放松心情有时会增加焦虑,不管怎样,这一个月都坚持下来了,接下来就是安心备战考研啦,可能会很长一段时间不更文,各位uu尽情谅解⏲️
最后希望正在看这篇文章的uu,蓝桥都能取得好成绩!!!
蓝桥杯,咱们有缘江湖再见呀!