2020年蓝桥杯Java B组第二场题目+部分个人解析

#A:门牌制作 624

解一:

public static void main(String[] args) {int count=0;for(int i=1;i<=2020;i++) {int n=i;while(n>0) {if(n%10==2) {count++;}n/=10;}}System.out.println(count);}

解二: 

public static void main(String[] args) {int cnt=0;for (int i = 1; i <= 2020; i++) {String s=i+"";for (int j = 0; j < s.length(); j++) {if(s.charAt(j)=='2') cnt++;}}System.out.println(cnt);}

#寻找 2020  16520

public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner = new Scanner(System.in);char[][] ch = new char[300][300];long sum = 0 ;for (int i = 0; i < ch.length; i++) {ch[i] = scanner.nextLine().toCharArray();}for (int i = 0; i < ch.length; i++) {for (int j = 0; j < ch[0].length; j++) {if (j+3<ch[0].length) {if (ch[i][j]=='2' && ch[i][j+1]=='0' &&ch[i][j+2]=='2' &&ch[i][j+3]=='0' ) {sum++;}}if (i+3<ch.length) {if (ch[i][j]=='2' && ch[i+1][j]=='0' &&ch[i+2][j]=='2' &&ch[i+3][j]=='0') {sum++;}}if (i+3<ch.length && j+3<ch[0].length) {if (ch[i][j]=='2' && ch[i+1][j+1]=='0' &&ch[i+2][j+2]=='2' &&ch[i+3][j+3]=='0') {sum++;}}}}System.out.println(sum);//16520}


#C: 蛇形填数 761

解题思路:先手写几行就可以发现,第一行第一列的值为1,第二行第二列的值为5.第三行第三列的值为13,第四行第四列的值为25,仔细观察就可以发现第i行第i列的值为  a = a + (i*4)。

public static void main(String[] args) {// TODO Auto-generated method stubint sum = 1;for (int i = 0; i < 20; i++) {sum = sum + (i * 4);}System.out.println(sum);}

#D:七段码dfs)  80


  解一:

static int[][] list = new int[][]{{0,1,0,0,0,1,0},{1,0,1,0,0,0,1},{0,1,0,1,0,0,1},{0,0,1,0,1,0,0},{0,0,0,1,0,1,1},{1,0,0,0,1,0,1},{0,1,1,0,1,1,0},};static Set<Set<Integer>> set = new HashSet<>();static boolean[] booleans = new boolean[7];public static void main(String[] args) {Scanner sc = new Scanner(System.in);ArrayList<Integer> arr = new ArrayList<>();for (int i = 0 ; i < 7 ; i++){booleans[i] = true;arr.add(i);set.add(new HashSet<>(arr));dfs(arr);booleans[i] = false;arr.remove(arr.size()-1);}System.out.println(set.size());}private static void dfs(ArrayList<Integer> arr) {set.add(new HashSet<>(arr));int last = arr.get(arr.size()-1);for (int i = 0 ; i < list[last].length ; i++){if (list[last][i] == 1 && !booleans[i]){booleans[i] = true;arr.add(i);dfs(arr);booleans[i] = false;arr.remove(arr.size()-1);}}}

  解二:

public static void main(String[] args) {creatGraph();dfs(1);System.out.println(count);}private static void creatGraph() {arr[1][2] = arr[1][6] = 1;arr[2][1] = arr[2][7] = arr[2][3] = 1;arr[3][2] = arr[3][4] = arr[3][7] = 1;arr[4][3] = arr[4][5] = 1;arr[5][4] = arr[5][6] = arr[5][7] = 1;arr[6][1] = arr[6][5] = arr[6][7] = 1;}private static void dfs(int k) {if (k > 7) {check();int q = 0;for (int i = 1; i <= 7; i++) {if (v[i] && res[i] == i) {q++;}}if (q == 1)count++;return;}v[k] = true;dfs(k + 1);v[k] = false;dfs(k + 1);}private static void check() {for (int i = 1; i <= 7; i++) {res[i] = i;}for (int i = 1; i <= 7; i++) {for (int j = 1; j <= 7; j++) {if (arr[i][j] != 0 && v[i] && v[j]) {int fx = find(i), fy = find(j);if (fx != fy) {res[fx] = fy;}}}}}private static int find(int p) {if (res[p] == p) {return p;} else {res[p] = find(res[p]);return res[p];}}

解三:

 static ArrayList<Integer>[] list;static HashSet<Integer> set = new HashSet<Integer>();public static void main(String[] args) {init();for(int i=0; i<7; ++i) {vis[0] = i;set.add(1<<i);dfs(1, 1<<i);}System.out.println(set.size());}static int[] vis = new int[7];public static void dfs(int n, int v) {for(int i=0; i<n; ++i) {for(int t : list[vis[i]]) {int p = v|(1<<t);if(!set.contains(p)) {set.add(p);vis[n] = t;dfs(n+1, p);}}}}public static void init() {//存储七位数的关系 list = new ArrayList[7];for(int i=0; i<7; ++i) {list[i] = new ArrayList<Integer>();}list[0].add(1);list[0].add(5);list[1].add(0);list[1].add(6);list[1].add(2);list[2].add(1);list[2].add(3);list[2].add(6);list[3].add(2);list[3].add(4);list[4].add(3);list[4].add(5);list[4].add(6);list[5].add(0);list[5].add(4);list[5].add(6);list[6].add(1);list[6].add(2);list[6].add(4);list[6].add(5);}

#E:排序  jonmlkihgfedcba

--------------------------------------------------------------------

--------------------------------------------------------------------

#F:成绩分析模拟、暴力)

public static void main(String[] args) {Scanner sc=new Scanner(System.in);int n=sc.nextInt();int a,max=0,min=100;double sum=0;for(int i=0;i<n;i++) {a=sc.nextInt();if(max<a) {max=a;}if(min>a) {min=a;}sum+=a;}System.out.println(max);System.out.println(min);System.out.printf("%.2f",sum/n);}


#G:单词分析字符串)

 

public static void main(String[] args) {Scanner sc=new Scanner(System.in);String str=sc.next();int[]arr =new int[26];int a=0;;char ch = 'a';for(int i=0;i<str.length();i++) {arr[str.charAt(i)-97]++;if(arr[str.charAt(i)-97]>a) {a=arr[str.charAt(i)-97];ch=str.charAt(i);}else if(arr[str.charAt(i)-97]==a) {if(ch-str.charAt(i)>0) {a=arr[str.charAt(i)-97];ch=str.charAt(i);}}}System.out.println(ch); System.out.println(a);}

#H: 数字三角形DP)


   

 public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n=scanner.nextInt();int [][]arr=new int[n+1][n+1];for (int i = 1; i < arr.length; i++) {for (int j = 1; j <= i; j++) {int s=scanner.nextInt();arr[i][j]=s+Math.max(arr[i-1][j-1],arr[i-1][j]);}}System.out.println(n%2==1?arr[n][n/2+1]:Math.max(arr[n][n/2],arr[n][n/2+1]));}}

  解二:

  public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();//base case : f(1) = a1int[][] dp = new int[n][n+1];int temp = scanner.nextInt();dp[0][0] = temp;int max = Integer.MIN_VALUE;for (int i = 2; i <= n; i++) {for (int j = 0; j < i; j++) {temp = scanner.nextInt();if (j != 0 && j != (i-1)) {dp[i-1][j] = Integer.max(dp[i-2][j-1],dp[i-1][j])+temp;}else if (j == 0) {dp[i-1][j] = dp[i-2][j]+temp;}else {dp[i-1][j] = dp[i-2][j-1]+temp;}if(dp[i-1][j] > max)max = dp[i-1][j];}dp[i-1][n] = max;max = Integer.MIN_VALUE;}System.out.println(dp[n-1][n]);scanner.close();}

# I:子串分值和规律题吧)

 

解一:   

 public static void main(String[] args) {Scanner sc = new Scanner(System.in);int[] arr = new int[26];long res = 0;for(int i = 0;i < 26;i++){arr[i] = -1;}String s = sc.nextLine();String[] str = s.split("");int willIndex = str.length;for(int i = 0;i < str.length;i++){int lastIndex = arr[str[i].charAt(0)-97];res += (long)(i - lastIndex)*(willIndex - i);arr[str[i].charAt(0)-97] = i;}System.out.println(res);}

  解二:

public static void main(String[] args) {Scanner sc = new Scanner(System.in);String str = sc.next();int[] nums = new int[26];long res = 0;long n = str.length();str = "0"+str;for (int i = 1; i < str.length(); i++) {res += (i - nums[str.charAt(i) - 'a']) * (n - i+1);nums[str.charAt(i) - 'a'] = i;}System.out.println(res);}

#J: 装饰珠

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/26800.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据结构:反射 和 枚举

目录 一、反射 1、定义 2、反射相关的类 3、Class类 &#xff08;2&#xff09;常用获得类中属性相关的方法&#xff1a; &#xff08;3&#xff09;获得类中注解相关的方法&#xff1a; &#xff08;4&#xff09;获得类中构造器相关的方法&#xff1a; &#xff08;…

QT-对象树

思维导图 写1个Widget窗口&#xff0c;窗口里面放1个按钮&#xff0c;按钮随便叫什么 创建2个Widget对象 Widget w1,w2 w1.show() w2不管 要求&#xff1a;点击 w1.btn ,w1隐藏&#xff0c;w2显示 点击 w2.btn ,w2隐藏&#xff0c;w1 显示 #include <QApplication> #inc…

LLMs之DeepSeek:DeepSeek-V3/R1推理系统的架构设计和性能统计的简介、细节分析之详细攻略

LLMs之DeepSeek&#xff1a;DeepSeek-V3/R1推理系统的架构设计和性能统计的简介、细节分析之详细攻略 目录 DeepSeek-V3/R1推理系统的架构设计 1、大规模跨节点专家并行 (EP) 2、计算-通信重叠 3、负载均衡 4、在线推理系统图 DeepSeek-V3/R1推理系统的架构设计 2025年3月…

开启AI短剧新纪元!SkyReels-V1/A1双剑合璧!昆仑万维开源首个面向AI短剧的视频生成模型

论文链接&#xff1a;https://arxiv.org/abs/2502.10841 项目链接&#xff1a;https://skyworkai.github.io/skyreels-a1.github.io/ Demo链接&#xff1a;https://www.skyreels.ai/ 开源地址&#xff1a;https://github.com/SkyworkAI/SkyReels-A1 https://github.com/Skywork…

苹果廉价机型 iPhone 16e 影像系统深度解析

【人像拍摄差异】 尽管iPhone 16e支持后期焦点调整功能&#xff0c;但用户无法像iPhone 16系列那样通过点击屏幕实时切换拍摄主体。前置摄像头同样缺失人像深度控制功能&#xff0c;不过TrueTone原彩闪光灯系统在前后摄均有保留。 很多人都高估了 iPhone 的安全性&#xff0c;查…

中科大计算机网络原理 1.5 Internt结构和ISP

一、互联网的层次化架构 ‌覆盖范围分层‌ ‌主干网&#xff08;Tier-1级&#xff09;‌ 国家级或行业级核心网络&#xff0c;承担跨区域数据传输和全球互联功能。例如中国的四大主干网&#xff08;ChinaNET、CERNET等&#xff09;以及跨国运营商&#xff08;如AT&T、Deuts…

线程 -- 线程池

线程池 谈起线程池之前&#xff0c;我们可以联想到常量池&#xff0c;那什么是常量池呢&#xff1f; 常量池&#xff1a;字符串常量&#xff0c;在 Java 程序最初构建的时候&#xff0c;就已经准备好了。等程序运行的时候&#xff0c;这样的常量也就加载到内存中了。因此剩下…

uniapp-原生android插件开发摘要

uni-app在App侧的原生扩展插件&#xff0c;支持使用java、object-c等原生语言编写&#xff0c;从HBuilderX 3.6起&#xff0c;新增支持了使用uts来开发原生插件。 基础项目 UniPlugin-Hello-AS工程请在App离线SDK中查找 基础项目(App离线SDK)已经配置好了自定义插件所需要的…

Hive-05之查询 分组、排序、case when、 什么情况下Hive可以避免进行MapReduce

一、目标 掌握hive中select查询语句中的基本语法掌握hive中select查询语句的分组掌握hive中select查询语句中的join掌握hive中select查询语句中的排序 二、要点 1. 基本查询 注意 SQL 语言大小写不敏感SQL 可以写在一行或者多行关键字不能被缩写也不能分行各子句一般要分行…

MacDroid for Mac v2.3 安卓手机文件传输助手 支持M、Intel芯片 4.7K

MacDroid 是Mac毒搜集到的一款安卓手机文件传输助手&#xff0c;在Mac和Android设备之间传输文件。您只需要将安卓手机使用 USB 连接到 Mac 电脑上即可将安卓设备挂载为本地磁盘&#xff0c;就像编辑mac磁盘上的文件一样编辑安卓设备上的文件&#xff0c;MacDroid支持所有 Andr…

题解:洛谷 P2199 最后的迷宫

题目https://www.luogu.com.cn/problem/P2199 显然&#xff0c;数据最大 &#xff0c;数组我们开不下&#xff0c;动态开数组。 对于每一个查询&#xff0c;从起点开始&#xff0c;走一步判断是否能看到火焰杯。 如果已经没法走了&#xff0c;直接拆墙&#xff0c;输出 Poor…

如何在Github上面上传本地文件夹

前言 直接在GitHub网址上面上传文件夹是不行的&#xff0c;需要一层一层创建然后上传&#xff0c;而且文件的大小也有限制&#xff0c;使用Git进行上传更加方便和实用 1.下载和安装Git Git - Downloads 傻瓜式安装即可 2.获取密钥对 打开自己的Github&#xff0c;创建SSH密钥&…

vscode接入ai插件(免费版)

一、安装插件 扩展程序搜索tongyilingma 点击install安装 二、登录阿里云 安装好之后左侧会出现通义的图标。 点击通义图标&#xff0c;右上角登录。 登陆成功后即可使用。 三、位置 在左边可能不太符合编码习惯&#xff0c;我们点击右侧位置图标&#xff0c;把通义图标拖…

【deepseek第二课】docker部署dify,配置私有化知识库,解决网络超时,成功安装

【deepseek第二课】docker部署dify,配置私有化知识库,解决网络超时,成功安装 1. dify安装1.1 官网安装文档介绍1.2 安装报错,网络连接问题使用镜像加速器处理1.3 dify后台启动很多docker进程2. 页面探索2.1 设置管理账号2.2 添加ollama支持的模型3. 创建知识库4. 创建一个聊…

如何利用SpringSecurity进行认证与授权

目录 一、SpringSecurity简介 1.1 入门Demo 二、认证 ?编辑 2.1 SpringSecurity完整流程 2.2 认证流程详解 ?2.3 自定义认证实现 2.3.1 数据库校验用户 2.3.2 密码加密存储 2.3.3 登录接口实现 2.3.4 认证过滤器 2.3.5 退出登录? 三、授权 3.1 权限系统作用 …

非平稳时间序列分析(二)——ARIMA(p, d, q)模型

此前篇章&#xff08;平稳序列&#xff09;&#xff1a; 时间序列分析&#xff08;一&#xff09;——基础概念篇 时间序列分析&#xff08;二&#xff09;——平稳性检验 时间序列分析&#xff08;三&#xff09;——白噪声检验 时间序列分析&#xff08;四&#xff09;—…

【软考-架构】1.2、指令系统-存储系统-cache

GitHub地址&#xff1a;https://github.com/tyronczt/system_architect ✨资料&文章更新✨ 指令系统 计算机指令执行过程&#xff1a;取指令一一分析指令一一执行指令三个步骤&#xff0c;首先将程序计数器PC中的指令地址取出&#xff0c;送入地址总线&#xff0c;CPU依据…

家用可燃气体探测器——家庭燃气安全的坚实防线

随着社会的发展和变迁&#xff0c;天然气为我们的生活带来了诸多便利&#xff0c;无论是烹饪美食&#xff0c;还是温暖取暖&#xff0c;都离不开它的支持。然而&#xff0c;燃气安全隐患如影随形&#xff0c;一旦发生泄漏&#xff0c;可能引发爆炸、火灾等严重事故&#xff0c;…

鸿蒙 ArkUI 实现敲木鱼小游戏

敲木鱼是一款具有禅意的趣味小游戏&#xff0c;本文将通过鸿蒙 ArkUI 框架的实现代码&#xff0c;逐步解析其核心技术点&#xff0c;包括动画驱动、状态管理、音效震动反馈等。 一、架构设计与工程搭建 1.1 项目结构解析 完整项目包含以下核心模块&#xff1a; ├── entry…

分布式日志和责任链路

目录 日志问题 责任链问题 分布式日志 GrayLog简介 部署安装 收集日志 配置Inputs 集成微服务 日志回收策略 搜索语法 搜索语法 自定义展示字段 日志统计仪表盘 创建仪表盘 链路追踪 APM 什么是APM 原理 技术选型 Skywalking简介 部署安装 微服务探针 整合…