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

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

目录

卡片

原题链接

问题描述

todo:这里复制题目描述

解题思路

从 1 开始拼,1 是最先被用到的,换句话说 1 是最先用完的,如果拼完当前数字后,1 的数量 < 0了,那么这个数字肯定拼不出来。

参考代码

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 cnt = 2021; for (int i = 1; ; i++) {
int t = i; while (t > 0) {
cnt -= t % 10 == 1? 1: 0; t /= 10; } if (cnt < 0) {
out.println(i - 1); break; } } out.flush(); in.close(); } }

路径

原题链接

问题描述

在这里插入图片描述

解题思路

前置知识:最小公倍数/最大公约数/dijkstra求单源最短路

参考代码

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 INF = 0x3f3f3f3f; static int N = 2050; static int[] dis = new int[N]; static boolean[] st = new boolean[N]; static List
> g = new ArrayList<>(); public static int gcd(int a, int b) {
return b == 0? a: gcd(b, a % b); } public static int lcm(int a, int b) {
return a * b / gcd(a, b); } public static void dijkstra() {
Arrays.fill(dis, INF); dis[1] = 0; PriorityQueue
pq = new PriorityQueue<>((a, b) -> (a[1] - b[1])); pq.offer(new int[] {
1, 0}); while (!pq.isEmpty()) {
int[] t = pq.poll(); if (st[t[0]]) continue; st[t[0]] = true; for (int[] next: g.get(t[0])) {
if (dis[t[0]] + next[1] < dis[next[0]]) {
dis[next[0]] = dis[t[0]] + next[1]; pq.offer(new int[] {
next[0], dis[next[0]]}); } } } out.println(dis[2021]); } public static void main(String[] args) throws Exception {
for (int i = 0; i <= 2021; i++) g.add(new ArrayList<>()); for (int i = 1; i <= 2021; i++) {
int ed = Math.min(2021, i + 21); for (int j = i + 1; j <= ed; j++) {
int d = lcm(i, j); g.get(i).add(new int[] {
j, d}); g.get(j).add(new int[] {
i, d}); } } dijkstra(); 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))); public static void main(String[] args) throws Exception {
int mx = 0; int[] cnt = new int[26]; String s = in.readLine(); for (char c: s.toCharArray()) {
cnt[c - 'A']++; mx = Math.max(mx, cnt[c - 'A']); } for (int i = 0; i < 26; i++) {
if (cnt[i] == mx) out.print((char)(i + 'A')); } out.flush(); in.close(); } }

费用报销

原题链接

问题描述

todo:这里复制题目描述

解题思路

01背包问题变种 详细题解可以看

参考代码

todo:这里是参考代码

转载地址:https://blog.csdn.net/qq_53655497/article/details/129520559 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

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

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月24日 15时24分25秒