第十四届蓝桥杯三月真题刷题训练——第 13 天
发布日期:2024-04-20 22:46:42 浏览次数:1 分类:技术文章

本文共 3737 字,大约阅读时间需要 12 分钟。

目录

特殊日期

原题链接

问题描述

todo:这里复制题目描述

解题思路

模拟即可

参考代码

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(); } }

重合次数

原题链接

问题描述

todo:这里复制题目描述

解题思路

模拟即可,每 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(); } }

左移右移

原题链接

问题描述

todo:这里复制题目描述

解题思路

每个数的初始权重是它本身,如果移动到最左端,那么它的权重就会变成最小值,最右端同理,最后根据权重排序即可。

参考代码

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

原题链接

问题描述

todo:这里复制题目描述

解题思路

梗子哥这篇题解写的非常的清楚了

参考代码

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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:第十四届蓝桥杯三月真题刷题训练——第 14 天
下一篇:第十四届蓝桥杯三月真题刷题训练——第 12 天

发表评论

最新留言

不错!
[***.144.177.141]2024年04月11日 07时03分05秒