蓝桥杯 2020年省赛真题 (Java 大学C组)

先挂着,重复的题就不写了


#A 指数计算

本题总分:5 分


问题描述

7 月 1 日是建党日,从 1921 年到 2020 年,中国共产党已经带领中国人民
走过了 99 年。
请计算: 7 2020 7^{2020} 72020 mod 1921,其中 A mod B 表示 A 除以 B 的余数。


答案提交

这是一道结果填空题,你只需要算出结果后提交即可。本题的结果为一个
整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。


480

calcCode:

System.out.print(new BigInteger("7").pow(2020).mod(new BigInteger("1921")));

或者写个快速幂,也建议写个快速幂,用不了多长时间还能沿用到后面

扫描二维码关注公众号,回复: 11955937 查看本文章
public class Test {
    
    
	
	static final int mod = 1921;
	
	public static void main(String[] args) {
    
    
		System.out.println(pow(7, 2020));
	}
	
	static int pow(int a, int n) {
    
    
		if (n == 0) return 1;
		if (n == 1) return a;
		if (0 == (n & 1)) return pow((a % mod) *(a % mod), n / 2) % mod;
		return ((a % mod) * (pow((a % mod) *(a % mod), n / 2) % mod)) % mod;
	}
}

#B 解密

本题总分:5 分


问题描述

小明设计了一种文章加密的方法:对于每个字母 c c c,将它变成某个另外的
字符 T c T_c Tc。下表给出了字符变换的规则:

在这里插入图片描述
例如,将字符串 YeRi 加密可得字符串 EaFn。
小明有一个随机的字符串,加密后为
EaFnjISplhFviDhwFbEjRjfIBBkRyY
(由 30 个大小写英文字母组成,不包含换行符),请问原字符串是多少?
(如果你把以上字符串和表格复制到文本文件中,请务必检查复制的内容
是否与文档中的一致。在试题目录下有一个文件 str.txt,第一行为上面的字符
串,后面 52 行依次为表格中的内容。)


答案提交

这是一道结果填空题,你只需要算出结果后提交即可。本题的结果为一个
只包含 30 30 30 个大小写英文字母的字符串,在提交答案时只填写这个字符串,填写
多余的内容将无法得分。


YeRikGSunlRzgDlvRwYkXkrGWWhXaA

calcCode:

import java.io.*;

public class Test {
    
    

    public static void main(String[] args) throws IOException {
    
    
        InputReader in = new InputReader(System.in, 200);
        int[] str = new int[30], table = new int[128];
        for (int i = 0; i < 30; i++)
            str[i] = in.nextChar();
        for (int i = 0; i < 52; i++) {
    
    
            int v = in.nextChar(), w = in.nextChar();
            table[w] = v;
        }
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < 30; i++)
            out.appendCodePoint(table[str[i]]);
        System.out.print(out);
    }

    static class InputReader {
    
    

        InputStream in;
        int next, len;
        byte[] buff;

        InputReader(InputStream in) {
    
     this(in, 8192); }

        InputReader(InputStream in, int buffSize) {
    
    
            this.buff = new byte[buffSize];
            this.next = this.len = 0;
            this.in = in;
        }

        int getByte() {
    
    
            if (next >= len)
                try {
    
    
                    next = 0;
                    len = in.read(buff);
                    if (len == -1) return -1;
                } catch (IOException e) {
    
     }
            return buff[next++];
        }

        int nextChar() {
    
    
            int c = getByte();
            while (c <= 32 || c == 127) c =getByte();
            return c;
        }
    }
}

写了个输入流
再打个表,结果就出来了


#C 跑步训练

本题总分:10 分


问题描述

小明要做一个跑步训练。
初始时,小明充满体力,体力值计为 10000。如果小明跑步,每分钟损耗
600 的体力。如果小明休息,每分钟增加 300 的体力。体力的损耗和增加都是
均匀变化的。
小明打算跑一分钟、休息一分钟、再跑一分钟、再休息一分钟……如此循
环。如果某个时刻小明的体力到达 0,他就停止锻炼。
请问小明在多久后停止锻炼。为了使答案为整数,请以秒为单位输出答案。
答案中只填写数,不填写单位。


答案提交

这是一道结果填空题,你只需要算出结果后提交即可。本题的结果为一个
整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。


3880

calcCode:

public class Test {
    
    
	
	public static void main(String[] args) {
    
    
		int i = -60, j, n = 10000 - 300;
		while (n > 0) {
    
    
			n += 300;
			i += 60;
			for (j = i + 60; i < j && n > 0; i++)
				n -= 10;
		}
		System.out.print(i);
	}
}

#D 合并检测

本题总分:10 分


问题描述

新冠疫情由新冠病毒引起,最近在 A 国蔓延,为了尽快控制疫情,A 国准
备给大量民众进病毒核酸检测。
然而,用于检测的试剂盒紧缺。
为了解决这一困难,科学家想了一个办法:合并检测。即将从多个人(k
个)采集的标本放到同一个试剂盒中进行检测。如果结果为阴性,则说明这 k
个人都是阴性,用一个试剂盒完成了 k 个人的检测。如果结果为阳性,则说明
至少有一个人为阳性,需要将这 k 个人的样本全部重新独立检测(从理论上看,
如果检测前 k − 1 个人都是阴性可以推断出第 k 个人是阳性,但是在实际操作中
不会利用此推断,而是将 k 个人独立检测),加上最开始的合并检测,一共使用
了 k + 1 个试剂盒完成了 k 个人的检测。
A 国估计被测的民众的感染率大概是 1%,呈均匀分布。请问 k 取多少能
最节省试剂盒?


答案提交

这是一道结果填空题,你只需要算出结果后提交即可。本题的结果为一个
整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。


10

calcCode:

public class Main {
    
    

    public static void main(String[] args) {
    
    
        int MAX = 10000, min = 0x7ffffff, res = 0;
        for (int i = 2; i <= MAX; i++) {
    
    
            int cnt = MAX / i + MAX / 100 * i + (MAX % i == 0? 0: 1);
            if (cnt < min) {
    
    
                min = cnt;
                res = i;
            }
        }
        System.out.print(res);
    }
}

因为没给出具体人数,所以读半天没读读懂题

枚举就完事了


#E REPEAT 程序

本题总分:15 分


问题描述

附件 prog.txt 中是一个用某种语言写的程序。
其中 REPEAT k 表示一个次数为 k 的循环。循环控制的范围由缩进表达,
从次行开始连续的缩进比该行多的(前面的空白更长的)为循环包含的内容。
例如如下片段:

REPEAT 2:
	A = A + 4
	REPEAT 5:
		REPEAT 6:
			A = A + 5
		A = A + 7
	A = A + 8
A = A + 9

该片段中从 A = A + 4 所在的行到 A = A + 8 所在的行都在第一行的
循环两次中。
REPEAT 6: 所在的行到 A = A + 7 所在的行都在 REPEAT 5: 循环中。
A = A + 5 实际总共的循环次数是 2 × 5 × 6 = 60 次。
请问该程序执行完毕之后,A 的值是多少?


答案提交

这是一道结果填空题,你只需要算出结果后提交即可。本题的结果为一个
整数,在提交答案时只填写这个整数,填写多余的内容将无法得分


241830

calcCode:

啊这
首先确认一下是否只包含 REPEAT、A、+、常量、= 这几种语句

Scanner in = new Scanner(new FileInputStream("prog.txt"));
Map<String, Integer> map = new HashMap();
while (in.hasNext()) {
    
    
	String now = in.next();
	Integer cnt = map.get(now);
	if (cnt == null) map.put(now, 1);
	else map.put(now, cnt + 1);
}
for (Entry<String, Integer> e: map.entrySet())
	System.out.println(e.getKey() + ": " + e.getValue());

确实只有这几种,那就好办了,递归求出每一句 REPEAT 里A的增量,再乘以 REPEAT 后的参数 return

好我放弃了
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
第一次觉得python这么香


#F 分类计数

时间限制: 1.0s 内存限制: 512.0MB 本题总分:15 分


问题描述

输入一个字符串,请输出这个字符串包含多少个大写字母,多少个小写字
母,多少个数字。


输入格式

输入一行包含一个字符串。


输出格式

输出三行,每行一个整数,分别表示大写字母、小写字母和数字的个数。


测试样例1

Input:
1+a=Aab

Output:
1
3
1

评测用例规模与约定

对于所有评测用例,字符串由可见字符组成,长度不超过 100。


code:

import java.io.*;

public class Main {
    
    

    public static void main(String[] args) throws IOException {
    
    
        byte[] buff = new byte[100];
        int len = System.in.read(buff), a = 0, b = 0, c = 0;
        for (int i = 0; i < len; i++) {
    
    
            if (buff[i] >= 'a' && buff[i] <= 'z') b++;
            else if (buff[i] >= 'A' && buff[i] <= 'Z') a++;
            else if (buff[i] >= '0' && buff[i] <= '9') c++;
        }
        System.out.print(a + "\n" + b + "\n" + c);
    }
}

#G 整除序列

时间限制: 1.0s 内存限制: 512.0MB 本题总分:20 分


问题描述

有一个序列,序列的第一个数是 n,后面的每个数是前一个数整除 2,请输
出这个序列中值为正数的项。


输入格式

输入一行包含一个整数 n。


输出格式

输出一行,包含多个整数,相邻的整数之间用一个空格分隔,表示答案。


测试样例1

Input:
20

Output:
20 10 5 2 1

评测用例规模与约定

对于 80% 的评测用例,1 ≤ n ≤ 109
对于所有评测用例,1 ≤ n ≤ 1018


code:

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

public class Main {
    
    
	
	public static void main(String[] args) throws IOException {
    
    
		PrintWriter out = new PrintWriter(System.out);
		long n = nextLong(System.in);
		do {
    
    
			out.print(n);
			out.write(' ');
		} while ((n /= 2) > 0);
		out.close();
	}
	
	static long nextLong(InputStream in) throws IOException {
    
    
		long n = 0;
		int c = in.read();
		while (c < '0' || c > '9') c = in.read();
		while (c >='0' && c <='9') {
    
    
			n = n * 10 + c - '0';
			c = in.read();
		}
		return n;
	}
}

送分啦


#H 走方格

时间限制: 1.0s 内存限制: 512.0MB 本题总分:20 分


问题描述

在平面上有一些二维的点阵。
这些点的编号就像二维数组的编号一样,从上到下依次为第 1 至第 n 行,
从左到右依次为第 1 至第 m 列,每一个点可以用行号和列号来表示。
现在有个人站在第 1 行第 1 列,要走到第 n 行第 m 列。只能向右或者向下
走。
注意,如果行号和列数都是偶数,不能走入这一格中。
问有多少种方案。


输入格式

输入一行包含两个整数 n, m。


输出格式

输出一个整数,表示答案。


测试样例1

Input:
3 4

Output:
2

测试样例2

Input:
6 6

Output:
0

评测用例规模与约定

对于所有评测用例,1 ≤ n ≤ 30, 1 ≤ m ≤ 30。


code:

import java.io.IOException;
import java.io.InputStream;

public class Main {
    
    
	
	public static void main(String[] args) throws IOException {
    
    
		int n = nextInt(System.in), m = nextInt(System.in);
		if (0 == (n & 1) && 0 == (m & 1)) System.out.print('0');
		else {
    
    
			int[][] dp = new int[n + 1][m + 1];
			for (int i = 2; i <= n; i += 2)
				for (int j = 2; j <= m; j += 2) dp[i][j] = -1;
			dp[0][1] = 1;
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= m; j++) {
    
    
					if (dp[i][j] == -1) dp[i][j] = 0;
					else dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				}
			System.out.print(dp[n][m]);
		}
	}
	
	static int nextInt(InputStream in) throws IOException {
    
    
		int n = 0, c = in.read();
		while (c < '0' || c > '9') c = in.read();
		while (c >='0' && c <='9') {
    
    
			n = n * 10 + c - '0';
			c = in.read();
		}
		return n;
	}
}

介不还是送分吗


#I 字符串编码

时间限制: 1.0s 内存限制: 512.0MB 本题总分:25 分


问题描述

小明发明了一种给由全大写字母组成的字符串编码的方法。对于每一个大
写字母,小明将它转换成它在 26 个英文字母中序号,即 A → 1, B → 2, … Z →
26。
这样一个字符串就能被转化成一个数字序列:
比如 ABCXYZ → 123242526。
现在给定一个转换后的数字序列,小明想还原出原本的字符串。当然这样
的还原有可能存在多个符合条件的字符串。小明希望找出其中字典序最大的字
符串。


输入格式

一个数字序列


输出格式

一个只包含大写字母的字符串,代表答案


测试样例1

Input:
123242526

Output:
LCXYZ

评测用例规模与约定

对于 20% 的评测用例,输入的长度不超过 20。
对于所有评测用例,输入的长度不超过 200000。


code:

import java.io.*;

public class Main {
    
    

    static byte[] chars = {
    
     0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90 };

    public static void main(String[] args) throws IOException {
    
    
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String line = in.readLine();
        int flag = 0;
        if (line.charAt(line.length() - 1) == '0') flag = 2;
        int pre = 0;
        for (int i = 0, h = line.length() - flag; i < h; i++) {
    
    
            pre = pre * 10 + (line.charAt(i) & 0xf);
            if (pre < 10) continue;
            if (pre > 26) {
    
    
                out.write(chars[pre / 10]);
                pre %= 10;
            } else if (pre > 10) {
    
    
                out.write(chars[pre]);
                pre = 0;
            }
        }
        if (pre != 0) out.write(chars[pre]);
        if (flag > 0) out.write(chars[(line.charAt(line.length() - 2) - '0') * 10]);
        out.close();
    }
}

打了个表,做了两个特判

一个是否输出完的判断,一个是结尾是否能单独组成一个字母的判断


#J 整数小拼接

时间限制: 1.0s 内存限制: 512.0MB 本题总分:25 分


问题描述

给定义个长度为 n n n 的数组 A 1 , A 2 , ⋅ ⋅ ⋅ , A n A_1, A_2, · · · , A_n A1,A2,,An。你可以从中选出两个数 A i A_i Ai A j A_j Aj
( i i i 不等于 j j j),然后将 A i A_i Ai A j A_j Aj 一前一后拼成一个新的整数。例如 12 和 345 可
以拼成 12345 或 34512 。注意交换 A i A_i Ai A j A_j Aj 的顺序总是被视为 2 种拼法,即便
A i A_i Ai = A j A_j Aj 时。
请你计算有多少种拼法满足拼出的整数小于等于 K K K


输入格式

第一行包含 2 2 2 个整数 n n n K K K
第二行包含 n n n 个整数 A 1 , A 2 , ⋅ ⋅ ⋅ , A n A_1, A_2, · · · , A_n A1,A2,,An


输出格式

一个整数代表答案。


测试样例1

Input:
4 33
1 2 3 4

Output:
8

评测用例规模与约定

对于 30% 的评测用例,1 ≤ N N N ≤ 1000, 1 ≤ K ≤ 1 0 8 10^8 108, 1 ≤ Ai ≤ 1 0 4 10^4 104
对于所有评测用例,1 ≤ N N N ≤ 100000,1 ≤ K K K 1 0 10 10^{10} 1010,1 ≤ A i A_i Ai 1 0 9 10^9 109


code:

import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;

public class Main {
    
    

    static int n;
    static Number[] list;

    public static void main(String[] args) {
    
    
        buff = new byte[8192];
        in = System.in;
        n = nextInt();
        int c= getByte(), k = 0, klen = 0, cnt = 0;
        int[] kiv = new int[12];
        int[] lkiv = new int[12];
        list = new Number[n];
        while (c < '0' || c > '9') c = getByte();
        while (c >='0' && c <='9') {
    
    
            kiv[++klen] = k = k * 10 + c - '0';
            c = getByte();
        }
        for (int i = 1, n = 10; i <= klen; n *= 10, i++) lkiv[i] = k % n;
        for (int i = 0, num = 0, len = 0; i < n; num = 0, len = 0, i++) {
    
    
            while (c < '0' || c > '9') c = getByte();
            while (c >='0' && c <='9') {
    
    
                num = num * 10 + c - '0';
                c = getByte();
                len++;
            }
            list[i] = new Number(num, len);
        }
        Arrays.sort(list);
        for (int i = 0; i < n; i++) {
    
    
            int to = kiv[klen - list[i].len];
            if (list[i].value > lkiv[list[i].len]) to--;
            if (to < list[i].value) cnt += findI(to);
            else cnt += findI(to) - 1;
        }
        System.out.print(cnt);
    }

    static int findI(int num) {
    
    
        int l = 0, r = n;
        while (l < r) {
    
    
            int mid = (l + r) / 2;
            if (num >= list[mid].value) l = mid + 1;
            else r = mid;
        }
        return l;
    }

    static class Number implements Comparable<Number> {
    
    

        int value, len;

        Number(int value, int len) {
    
    
            this.value = value;
            this.len = len;
        }

        public int compareTo(Number num) {
    
     return this.value - num.value; }
    }

    static InputStream in;
    static int next, blen;
    static byte[] buff;
    static int getByte() {
    
    
        if (next >= blen)
            try {
    
    
                next = 0;
                blen = in.read(buff);
            } catch (IOException e) {
    
    
                e.fillInStackTrace();
            }
        return buff[next++];
    }

    static int nextInt() {
    
    
        int n = 0, c = getByte();
        while (c < '0' || c > '9') c = getByte();
        while (c >='0' && c <='9') {
    
    
            n = n * 10 + c - '0';
            c = getByte();
        }
        return n;
    }
}

写了个输入流处理,实现了录入有效数据时,记录数据长度

接下来就是枚举查找,每个项只去找能组成它左侧的数,而其他项又会把它当右侧来匹配,所以它们是完全的

然后做一些小小的细节处理

就完成了

猜你喜欢

转载自blog.csdn.net/qq_43449564/article/details/109094410