第十四届蓝桥杯三月真题刷题训练——第 10 天
发布日期:2024-04-20 22:46:09
浏览次数:1
分类:技术文章
本文共 3050 字,大约阅读时间需要 10 分钟。
目录
裁纸刀
原题链接
问题描述
解题思路
找规律,首先需要裁掉纸的边缘 4 刀,再看横向的,要裁 行数 - 1
刀,纵向的每一行都要裁掉 列数 - 1
刀。
参考代码
import java.io.*;import java.util.*;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 { out.println(4 + (20 - 1) + (21 * 20)); out.flush(); in.close(); }}
刷题统计
原题链接
问题描述
解题思路
数据范围很大,需要把一个周的刷题量看作一个整体来计算。
参考代码
import java.io.*;import java.util.*;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 { String[] s = in.readLine().split(" "); long a = Long.parseLong(s[0]), b = Long.parseLong(s[1]), p = Long.parseLong(s[2]); // 一周的刷题数量 long weekCnt = a * 5 + b * 2; // 刷题的周数 long weekSum = p / weekCnt; // 当前刷题天数 long ans = weekSum * 7; // 剩余的题目 p %= weekCnt; // 当前是星期一 int cur = 1; while (p > 0) { p -= cur <= 5? a: b; cur++; ans++; } out.println(ans); out.flush(); in.close(); }}
修剪灌木
原题链接
问题描述
解题思路
对于当前第 i 棵树,再修剪完之后下一次修剪的时间从两边取一个最大值即可,可以发现是左右对称的,计算左边再对称右边即可,省去了判断大小。
参考代码
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 n = Integer.parseInt(in.readLine()); int mid = n / 2; for (int i = 1; i <= mid; i++) { out.println((n - i) * 2); } if ((n & 1) == 1) out.println((n - mid - 1) * 2); for (int i = mid; i >= 1; i--) { out.println((n - i) * 2); } out.flush(); in.close(); }}
k倍区间
原题链接
问题描述
解题思路
前缀和 + 哈希表
很经典的套路题了,不了解的可以去看这两道题的灵神的题解参考代码
import java.io.*;import java.util.*;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, k; static int[] a = new int[N], pre = new int[N]; static Mapmap = new HashMap<>(); public static void main(String[] args) throws Exception { String[] s = in.readLine().split(" "); n = Integer.parseInt(s[0]); k = Integer.parseInt(s[1]); for (int i = 1; i <= n; i++) { a[i] = Integer.parseInt(in.readLine()); pre[i] = (pre[i - 1] + a[i]) % k; } long ans = 0L; for (int i = 0; i <= n; i++) { ans += map.getOrDefault(pre[i], 0); map.put(pre[i], map.getOrDefault(pre[i], 0) + 1); } out.println(ans); out.flush(); in.close(); }}
转载地址:https://blog.csdn.net/qq_53655497/article/details/129485121 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月20日 04时28分27秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【深度学习笔记】标准卷积
2019-04-30
【深度学习笔记】组卷积
2019-04-30
【深度学习笔记】循环神经网络和递归神经网络区别
2019-04-30
【学习笔记】英文科技论文常见英语句式积累
2019-04-30
【深度学习笔记】PixelShuffle
2019-04-30
【python3学习笔记】斜杠和双斜杠运算符的区别
2019-04-30
【深度学习笔记】用torch.nn.Sequential()搭建神经网络模型
2019-04-30
【深度学习笔记】用torch.nn.ModuleList搭建神经网络
2019-04-30
【深度学习笔记】pytorch的点乘(dot product)
2019-04-30
【深度学习笔记】残差
2019-04-30
【python学习笔记】读取指定文件夹中的图片,结合边缘保留滤波EPF
2019-04-30
【工具和环境】Linux下安装pycharm
2019-04-30
【Accumulation】The definition of SISR
2019-04-30