第十四届蓝桥杯三月真题刷题训练——第 13 天
发布日期:2024-04-20 22:46:42
浏览次数:1
分类:技术文章
本文共 3737 字,大约阅读时间需要 12 分钟。
目录
特殊日期
原题链接
问题描述
解题思路
模拟即可
参考代码
import java.util.*;import java.math.*;import java.io.*;public class Main { static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static int[] days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; public static boolean isLeap(int year) { return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0); } public static int check(int x) { int ans = 0; while (x > 0) { ans += x % 10; x /= 10; } return ans; } public static void main(String[] args) throws Exception { int ans = 0; for (int i = 1900; i <= 9999; i++) { days[2] = isLeap(i)? 29: 28; for (int j = 1; j <= 12; j++) { for (int k = 1; k <= days[j]; k++) { if (check(i) == check(j) + check(k)) ans++; } } } out.println(ans); out.flush(); in.close(); } }
重合次数
原题链接
问题描述
解题思路
模拟即可,每 60 秒就会重合一次。注意这个题有个坑,所以就是 60 分钟重合 59 次,折合一下就是每 61 秒重合一次。
参考代码
import java.util.*;import java.math.*;import java.io.*;public class Main { static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String[] args) throws Exception { int st = 6 * 60 * 60 + 13 * 60 + 22; int ed = 14 * 60 * 60 + 36 * 60 + 20; out.println((ed - st) / 61); out.flush(); in.close(); } }
左移右移
原题链接
问题描述
解题思路
每个数的初始权重是它本身,如果移动到最左端,那么它的权重就会变成最小值,最右端同理,最后根据权重排序即可。
参考代码
import java.util.*;import java.math.*;import java.io.*;public class Main { static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static int N = (int)2e5 + 10, n, m; static int[][] a = new int[N][2]; public static void main(String[] args) throws Exception { String[] s = in.readLine().split(" "); n = Integer.parseInt(s[0]); m = Integer.parseInt(s[1]); for (int i = 1; i <= n; i++) { a[i][1] = i; a[i][0] = i; } int st = 0, ed = n + 1; for (int i = 0; i < m; i++) { s = in.readLine().split(" "); int t = Integer.parseInt(s[1]); if (s[0].equals("L")) { a[t][0] = st--; } else { a[t][0] = ed++; } } Arrays.sort(a, 1, n + 1, (a, b) -> (a[0] - b[0])); for (int i = 1; i <= n; i++) out.print(a[i][1] + " "); out.flush(); in.close(); } }
近似gcd
原题链接
问题描述
解题思路
梗子哥这篇题解写的非常的清楚了
参考代码
import java.util.*;import java.math.*;import java.io.*;public class Main { static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static int N = (int)1e5 + 10, n, g; static int[] a = new int[N]; public static void main(String[] args) throws Exception { String[] s = in.readLine().split(" "); n = Integer.parseInt(s[0]); g = Integer.parseInt(s[1]); s = in.readLine().split(" "); for (int i = 1; i <= n; i++) { a[i] = Integer.parseInt(s[i - 1]) % g == 0? 1: 0; a[i] += a[i - 1]; } long ans = 0L; int start = 0; for (int end = 2; end <= n; end++) { while (start + 1 < end && a[end] - a[start] + 1 < end - start) start++; ans += end - start - 1; } out.println(ans); out.flush(); in.close(); } }
转载地址:https://blog.csdn.net/qq_53655497/article/details/129584010 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月11日 07时03分05秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Jquery触发父节点的a标签的点击事件
2019-04-30
在编写动态插入删除DOM元素时,Easyui控件渲染效果失败的问题
2019-04-30
Easyui动态添加控件无法渲染 $.parser.parse()无效
2019-04-30
Oracle反转倒置函数
2019-04-30
WebUpload 视频上传,支持多视频上传
2019-04-30
Js 校验“JSON”串格式aa:11;bb:22;
2019-04-30
让所有浏览器支持HTML5 video视频标签
2019-04-30
黑洞效果的粒子背景效果
2019-04-30
jQuery炫丽星空3d旋转星空
2019-04-30
原生js打印插件Print.js
2019-04-30
Oracle排序nulls last,nulls first ,nvl,case
2019-04-30
Oracle 查询类似 select top 的用法
2019-04-30
ORACLE WITH AS 用法
2019-04-30
JSTL中c:forEach循环里的值的substr操作及对String操作的常用API
2019-04-30
在foreach 里面调用js代码
2019-04-30
tomcat遇到断开的管道问题,一直还没查到问题
2019-04-30
清除陷入CLOSE_WAIT的进程
2019-04-30
Easyui comobox 下拉框必填校验
2019-04-30