第十四届蓝桥杯三月真题刷题训练——第 11 天

卡片

原题链接

卡片

问题描述

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<List<int[]>> 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<int[]> 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背包问题变种 详细题解可以看 lh 学长的这篇题解

参考代码

todo:这里是参考代码

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是第十四届蓝桥杯Python组真题的部分内容: 一、选择题(每题5分,共40分) 1. 下列哪个不是Python的内置数据类型? A. int B. float C. char D. str 答案:C 2. 下列哪个不是Python的保留字? A. and B. or C. not D. xor 答案:D 3. 下列哪个不是Python的标准模块? A. os B. sys C. math D. timeit 答案:D 4. 下列哪个Python库可以用于科学计算? A. NumPy B. SciPy C. Matplotlib D. All of the above 答案:D 5. 下列哪个Python库可以用于机器学习? A. TensorFlow B. Keras C. PyTorch D. All of the above 答案:D 6. 下列哪个Python库可以用于爬虫? A. Requests B. BeautifulSoup C. Scrapy D. All of the above 答案:D 7. 下列哪个Python库可以用于图像处理? . OpenCV B. Pillow C. Scikit-image D. All of the above 答案:D 8. 下列哪个Python库可以用于游戏开发? A. Pygame B. Panda3D C. PyOpenGL . All of the above 答案:D 二、编程题(每题20分,共60分) 1. 编写一个Python程序,输入一个字符串,将其中的大写字母转换为小写字母,将其中的小写字母转换为大写字母,然后输出转换后的字符串。 2. 编写一个Python程序,输入一个整数n,输出n的阶乘。 3. 编写一个Python程序,输入一个字符串,判断该字符串是否为回文字符串。如果是回文字符串,则输出True,否则输出False。 以上是部分内容,完整的第十四届蓝桥杯Python组真题可以在蓝桥杯官网上找到。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值