第十四届蓝桥杯三月真题刷题训练——第 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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值