第十四届蓝桥杯三月真题刷题训练——第 11 天
发布日期:2024-04-20 22:46:20
浏览次数:1
分类:技术文章
本文共 3183 字,大约阅读时间需要 10 分钟。
目录
卡片
原题链接
问题描述
解题思路
从 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(); } }
字符统计
原题链接
问题描述
解题思路
数组计数即可,维护最大的出现次数,没什么好说的。
参考代码
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(); } }
费用报销
原题链接
问题描述
解题思路
01背包问题变种 详细题解可以看
参考代码
todo:这里是参考代码
转载地址:https://blog.csdn.net/qq_53655497/article/details/129520559 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年04月24日 15时24分25秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
谈谈TOMCAT原理和机制
2019-04-30
事务和memory表
2019-04-30
程序员生涯的起步
2019-04-30
数据库糟糕的一天
2019-04-30
关于hadoop找不到class的问题
2019-04-30
mac安装hadoop可能遇到的问题
2019-04-30
python2 升级 python3 的一些变化
2019-04-30
C++ 的枚举 enum
2019-04-30
文件读写与字符串替换
2019-04-30
pybind11 工具转换 C++ 接口
2019-04-30
leetcode 222.完全二叉树的节点个数
2019-04-30
根据两种遍历方式构造二叉树
2019-04-30
leetcode 44. 通配符匹配
2019-04-30
662. 二叉树最大宽度
2019-04-30
剑指 Offer 36. 二叉搜索树与双向链表
2019-04-30
leetcode 82. 删除排序链表中的重复元素 II
2019-04-30
leetcode 1737. 满足三条件之一需改变的最少字符数
2019-04-30
leetcode 378. 有序矩阵中第K小的元素
2019-04-30
刚开始写博客,希望自己能坚持下来,希望能将自己的经验、感悟、知识留下来,助己及人。
2019-04-30
其实“水”题并不水,重视“水”题
2019-04-30