讲座配套题单的题解喵
每题的文字解释会逐渐补充,如果有疑问直接私信喵
目录
- 讲座配套题单的题解喵
- 目录
- A - 看看你会不会用电脑
- B - 求求你不要用内置函数
- C - GPA
- D - min
- E - for循环大神
- F - 居然有人说这个是线性代数
- G - 高三同学秒了
- H - 无穷级数
- I - 不要用内置函数😭
- J - 古人的wisdom
- K - 经常算组合数的同学都知道
- L - minmax
- M - 传奇读题大赛
- N - 博弈
- O - EZ?
- P - 你会不会暴力
- Q - 一点点🤏hard
- R - 比较真的真题
- S - 没什么难的
- T - 不准使用四重for循环!
- U - 漆黑的白
- V - 培训
- W - ABABA
- X - 来听讲座的在这里签到
- Y - 拓展题01:分类讨论
- Z - 超级无敌逆天传奇模拟题
- AB - 拓展2:挑战1994国际信息学奥林匹克竞赛顶级难题
- AC - 谁家地毯是空心的
- AD - 拓展3:传奇二分答案模板题
- AE - 中规中矩の模拟题
- AF - 排队的总和
- AG - 粉刷
A - 看看你会不会用电脑
https://vjudge.net/contest/666068#problem/A
你应该会写吧?
不会写的可以点击以下链接☝🤓
保姆教程!A+B不会写怎么办😱
a, b = map(int, input().split())def sol(a: int, b: int) -> int:print(a + b)sol(a, b)
B - 求求你不要用内置函数
https://vjudge.net/contest/666068#problem/B
num: str = input()def sol(num: str):# reversenum = num[::-1]print(float(num))sol(num)
C - GPA
https://vjudge.net/contest/666068#problem/C
a, b, c = map(int, input().split())def sol(a: int, b: int, c: int):print((a * 2 + b * 3 + c * 5) // 10)sol(a, b, c)
D - min
https://vjudge.net/contest/666068#problem/D
n = int(input())
lst = list(map(int, input().split()))def sol(n: int, lst: list):minn=114514for i in lst:if i < minn:minn = iprint(minn)# print(min(lst))sol(n, lst)
E - for循环大神
https://vjudge.net/contest/666068#problem/E
n:int = int(input())def sol(n: int):ans = 0cnt=1for i in range(1, n+1):cnt*=ians += cntprint(ans)
sol(n)
F - 居然有人说这个是线性代数
https://vjudge.net/contest/666068#problem/F
n: int = int(input())def sol(n: int):lst = [[0 for i in range(n)] for j in range(n)]dfs(lst, 0, 0, 1)# 每个数字有都会占用 3个字符,前面使用空格补齐。for i in lst:for j in i:print("%3d" % j, end="")# %3d 表示输出一个整数,占3个字符的位置,不够的用空格补齐print()dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
id = 0
cnt = 1def dfs(lst, x, y, cnt):global id, dx, dy, nif cnt > n * n:returnlst[x][y] = cntcnt += 1tx = x + dx[id]ty = y + dy[id]if tx < 0 or tx >= n or ty < 0 or ty >= n or lst[tx][ty] != 0:id = (id + 1) % 4tx = x + dx[id]ty = y + dy[id]dfs(lst, tx, ty, cnt)sol(n)
G - 高三同学秒了
https://vjudge.net/contest/666068#problem/G
n: int = int(input())def sol(n: int):if n == 0:print(0, end=".00")returna = 1b = 1for i in range(2, n):a, b = b, a + bprint(b, end=".00")sol(n)
H - 无穷级数
https://vjudge.net/contest/666068#problem/H
k: int = int(input())def sol(k: int):tot = 0cnt = 1while tot <= k:tot += 1 / cntcnt += 1print(cnt - 1)sol(k)
I - 不要用内置函数😭
https://vjudge.net/contest/666068#problem/I
n: int = int(input())def sol(n: int):negetive = n < 0n = abs(n)ans = 0while n:ans = ans * 10 + n % 10n //= 10if negetive:ans = -ansprint(ans)sol(n)
J - 古人的wisdom
https://vjudge.net/contest/666068#problem/J
n: int = int(input())def sol(n: int):cnt = 0while n:n //= 2cnt += 1print(cnt)sol(n)
K - 经常算组合数的同学都知道
https://vjudge.net/contest/666068#problem/K
如果你在纸上画一画 \(C[n][k]\) 是怎么递推的,你就会发现这个题目是一个经典的诈骗题目(指这个题目看似很难,但是实际上很简单)。
因为
\(C[n][0] = 1 =C[n][n]\)
而
\(C[n][k]\) = \(C[n-1][k-1]+C[n][k-1]\)
化成图表差不多就是这样的:
n\k 0 1 2 3 4 50
1 1
2 1 1
3 1 2 1
4 1 2 4 1
5 1 2 4 8 1
6 1 2 4 8 16 1
...
于是特判一下 \(k=0\) 或者 \(n=k\) 的情况,直接输出\(1\),否则输出 \(2^k\) 就可以了。
做题一定要多画画图,凭脑袋空想怎么能轻松发现规律呢(
t: int = int(input())
# list_n = [0] * t
# list_k = [0] * tlist_n = list(map(int, input().split()))
list_k = list(map(int, input().split()))# (10^9 + 7) 模数
p = 1000000007# print(list_n)
# print(list_k)# 快速幂算法,在O(logn)时间复杂度内求a^b % p的值
def fastpower(a: int, b: int, p: int) -> int:res = 1a %= pwhile b > 0:if b % 2 == 1:res = res * a % pa = a * a % pb //= 2return res# 计算函数
def calc(n: int, k: int) -> int:if k == 0 or n == k:return 1else:return fastpower(2, k, p)def sol(t: int, list_n: list, list_k: list) -> int:for i in range(t):n = list_n[i]k = list_k[i]print(calc(n, k))sol(t, list_n, list_k)
L - minmax
https://vjudge.net/contest/666068#problem/L
t: int = int(input())def sol(n: int, lst: list):lst.sort(reverse=True)if n > 1:lst[1], lst[n - 1] = lst[n - 1], lst[1]b = lst[0]c = lst[0]ans = 0for i in range(0, n):b = min(b, lst[i])c = max(c, lst[i])ans += c - bprint(ans)while t:n = int(input())lst = list(map(int, input().split()))sol(n, lst)t -= 1
M - 传奇读题大赛
https://vjudge.net/contest/666068#problem/M
这题如果这么写会超时()
def sol(n: int):ans = "1"for i in range(1, n):ans += "0"print(ans)
直接一位一位输出就没事
t: int = int(input())def sol(n: int):print(1, end="")for i in range(1, n):print(0, end="")print()while t:n = int(input())sol(n)t -= 1
N - 博弈
https://vjudge.net/contest/666068#problem/N
t: int = int(input())def sol(n: int, s: str):if s[0] == "1" or s[n-1] == "1":print("YES")else:for i in range(0, n - 1):if s[i] == "1" and s[i + 1] == "1":print("YES")returnprint("NO")while t:n = int(input())s = input()sol(n, s)t -= 1
O - EZ?
https://vjudge.net/contest/666068#problem/O
python 里的字符串是不可变的,所以不能直接修改字符串的某一位,只能通过新建一个字符串来实现。悲伤😭
t = int(input())def sol(a: str, b: str):print(b[0] + a[1] + a[2] + " " + a[0] + b[1] + b[2])while t:a, b = input().split()sol(a, b)t -= 1
P - 你会不会暴力
https://vjudge.net/contest/666068#problem/P
t: int = int(input())def sol(n: int):ans_x = 0ans_tot = 0for x in range(2, n + 1):k = n // xans = x * k * (k + 1) // 2if ans > ans_tot:ans_tot = ansans_x = xprint(ans_x)while t:n = int(input())sol(n)t -= 1
Q - 一点点🤏hard
https://vjudge.net/contest/666068#problem/Q
t: int = int(input())def sol(n: int, lst: list):max_num = lst[0]tot = 0ans = 0for i in lst:tot += iif i > max_num:max_num = iif tot == 2 * max_num:ans += 1print(ans)while t:n = int(input())lst = list(map(int, input().split()))sol(n, lst)t -= 1
R - 比较真的真题
https://vjudge.net/contest/666068#problem/R
t: int = int(input())# mp是list,里面的元素是str喵
def sol(n: int, m: int, mp: list):st_x = 0st_y = 0ed_x = 0ed_y = 0flag = 0for i in range(n):for j in range(m):if mp[i][j] == "#":if flag == 0:st_x = ist_y = jflag = 1ed_x = ied_y = jprint((st_x + ed_x) // 2 + 1, end=" ")print((st_y + ed_y) // 2 + 1)while t:n, m = map(int, input().split())mp = []for i in range(n):tmp: str = input()mp.append(tmp)sol(n, m, mp)t -= 1
S - 没什么难的
https://vjudge.net/contest/666068#problem/S
n: int = int(input())lst_a = list(map(int, input().split()))
lst_b = list(map(int, input().split()))def sol(n: int, lst_a: list, lst_b: list):lst_a.sort()lst_b.sort()print(lst_a[n - 1] + lst_b[n - 1])sol(n, lst_a, lst_b)
T - 不准使用四重for循环!
https://vjudge.net/contest/666068#problem/T
n: int = int(input())
lst_n = list(map(int, input().split()))m: int = int(input())
lst_m = list(map(int, input().split()))l: int = int(input())
lst_l = list(map(int, input().split()))q: int = int(input())
lst_q = list(map(int, input().split()))def sol(n, m, l, q, lst_n, lst_m, lst_l, lst_q):mp = dict()for i in lst_n:for j in lst_m:for k in lst_l:if i + j + k not in mp:mp[i + j + k] = 1for i in lst_q:if i in mp:print("Yes")else:print("No")sol(n, m, l, q, lst_n, lst_m, lst_l, lst_q)
U - 漆黑的白
https://vjudge.net/contest/666068#problem/U
t: int = int(input())def sol(n: int, wall: str):l = 0r = n - 1while wall[l] != "B":l += 1while wall[r] != "B":r -= 1print(r - l + 1)while t:n = int(input())wall = input()sol(n, wall)t -= 1
V - 培训
https://vjudge.net/contest/666068#problem/V
t: int = int(input())def sol(name: str, age: int, grade: int):print(name, end=" ")print(age + 1, end=" ")now_grade = int(grade * 1.2)print(now_grade if now_grade <= 600 else 600)while t:name, age, grade = input().split()age = int(age)grade = int(grade)sol(name, age, grade)t -= 1
W - ABABA
https://vjudge.net/contest/666068#problem/W
t: int = int(input())def sol(s: str):cnt_a = 0cnt_b = 0for i in s:if i == "A":cnt_a += 1else:cnt_b += 1print("A" if (cnt_a > cnt_b) else "B")while t:s = input()sol(s)t -= 1
X - 来听讲座的在这里签到
https://vjudge.net/contest/666068#problem/X
t: int = int(input())def sol(a: int, b: int):print(b - a)while t:a, b = map(int, input().split())sol(a, b)t -= 1
Y - 拓展题01:分类讨论
https://vjudge.net/contest/666068#problem/Y
n: int = int(input())
lst = list(map(int, input().split()))# 将整个多项式一位一位地输出
# 每一位的输出格式为:符号+绝对值+幂次
# 我们分成三个部分分别讨论
def sol(n: int, lst: list):now = n # 当前的幂次head = 1 # 是否为首位for a in lst:if a != 0:# 处理符号if head:if a < 0:print("-", end="")head = 0else:if a > 0:print("+", end="")else:print("-", end="")# 处理系数if now > 0 and abs(a) == 1:passelse:print(abs(a), end="")# 处理幂次if now > 1:print("x^", end="")print(now, end="")elif now == 1:print("x", end="")now -= 1sol(n, lst)
Z - 超级无敌逆天传奇模拟题
https://vjudge.net/contest/666068#problem/Z
python 代码稍显难写,但是思路就是用栈简单的模拟,下面是cpp的代码()
#include <bits/stdc++.h>
using namespace std;
struct dot
{char op, var;string st, ed;int ok = 0;
};
int toint(string &s)
{int res = 0;for (auto &i : s)res = res * 10 + (i - '0');return res;
}
void sol()
{int line, guess_time = 0;string guess;cin >> line >> guess;if (guess == "O(1)")guess_time = 0;elsefor (auto &i : guess)if (i >= '0' and i <= '9')guess_time = guess_time * 10 + (i - '0');vector<dot> arr(line);for (auto &i : arr){cin >> i.op;if (i.op == 'F')cin >> i.var >> i.st >> i.ed;}bool fg = 1;int cnt = 0;stack<char> st;map<char, int> mp;for (int i = 0; i < line; i++){if (arr[i].op == 'F'){if (mp[arr[i].var] == 1){fg = 0;break;}st.push(arr[i].var);mp[arr[i].var] = 1;}else{if (st.empty()){fg = 0;break;}mp[st.top()] = 0;st.pop();}}if (!st.empty())fg = 0;if (!fg){cout << "ERR" << endl;return;}for (auto &i : arr){if (i.st == "n" and i.ed == "n")i.ok = 0;else if (i.st == "n" and i.ed != "n")i.ok = -1;else if (i.st != "n" and i.ed != "n"){int st = toint(i.st), ed = toint(i.ed);if (st > ed)i.ok = -1;elsei.ok = 0;}elsei.ok = 1;}stack<int> dep;int ans = 0;for (auto &i : arr){if (i.op == 'F'){if (i.ok == 0){int tmp = (dep.empty() ? 0 : dep.top());dep.push(tmp);}else if (i.ok == -1)dep.push(-114);else{int tmp = (dep.empty() ? 0 : dep.top());if (tmp == -114)dep.push(-114);elsedep.push(tmp + 1);}ans = max(ans, dep.top());}elsedep.pop();}if (ans == guess_time)cout << "Yes" << endl;elsecout << "No" << endl;
}
int main()
{int t;cin >> t;while (t--)sol();return 0;
}
AB - 拓展2:挑战1994国际信息学奥林匹克竞赛顶级难题
https://vjudge.net/contest/666068#problem/AB
写记忆化搜索的话,不加优化过不了这道题,了解思想就可以了。
这里只能拿89分,TLE on test 8
n = int(input())mp = [[] for i in range(n)]for i in range(n):tmp = [int(i) for i in input().split()]mp[i] = tmp
dp = [[0] * n for i in range(n)]def dfs(x, y) -> int:if x == n - 1:dp[x][y] = mp[x][y]return dp[x][y]if dp[x][y] != 0:return dp[x][y]else:dp[x][y] = max(dfs(x + 1, y), dfs(x + 1, y + 1)) + mp[x][y]return dp[x][y]print(dfs(0, 0))
AC - 谁家地毯是空心的
https://vjudge.net/contest/666068#problem/AC
t: int = int(input())def sol():n, m = map(int, input().split())mp = [""] * nfor i in range(n):mp[i] = input()ans = 0times = min(n, m) // 2for i in range(times):line = ""for j in range(i, m - i):line += mp[i][j]for j in range(i + 1, n - i):line += mp[j][m - i - 1]for j in range(m - i - 2, i - 1, -1):line += mp[n - i - 1][j]for j in range(n - i - 2, i, -1):line += mp[j][i]for j in range(3):line += line[j]for j in range(3, len(line)):if (line[j - 3] == "1"and line[j - 2] == "5"and line[j - 1] == "4"and line[j] == "3"):ans += 1print(ans)while t:sol()t -= 1
AD - 拓展3:传奇二分答案模板题
https://vjudge.net/contest/666068#problem/AD
这个只能拿80分,会MLE,了解一下就行了。
n,m = map(int, input().split())
lst = list(map(int, input().split()))def sol(n,m,lst):def check(mid):cnt = 0for i in lst:cnt += max(0, i - mid)return cnt >= ml = 0r = 1000001while l+1<r:mid = (l+r)//2if check(mid):l = midelse:r = midprint(l)sol(n,m,lst)
AE - 中规中矩の模拟题
https://vjudge.net/contest/666068#problem/AE
n: int = int(input())def sol(n):lst = [[0] * (n + 1) for _ in range(n + 1)]lst[1][(n + 1) // 2] = 1last_x = 1last_y = (n + 1) // 2for i in range(2, n * n + 1):if last_x == 1 and last_y != n:last_x = nlast_y = last_y + 1elif last_y == n and last_x != 1:last_x = last_x - 1last_y = 1elif last_x == 1 and last_y == n:last_x = last_x + 1last_y = last_yelif last_x != 1 and last_y != n:if lst[last_x - 1][last_y + 1] == 0:last_x = last_x - 1last_y = last_y + 1else:last_x = last_x + 1last_y = last_ylst[last_x][last_y] = ifor i in range(1, n + 1):for j in range(1, n + 1):print(lst[i][j], end=" ")print()sol(n)
AF - 排队的总和
https://vjudge.net/contest/666068#problem/AF
t: int = int(input())def sol(n, m, r, c):print(m - c + (n - r) * (2 * m - 1))while t:n, m, r, c = map(int, input().split())sol(n, m, r, c)t -= 1
AG - 粉刷
https://vjudge.net/contest/666068#problem/AG
t: int = int(input())def sol(n: int, arr: list[int]):cnt1 = 0max1 = 0cnt2 = 0max2 = 0for i in range(0, n, 2):cnt1 += 1max1 = max(arr[i], max1)for i in range(1, n, 2):cnt2 += 1max2 = max(arr[i], max2)print(max(cnt1 + max1, cnt2 + max2))while t:n: int = int(input())arr: list[int] = list(map(int, input().split()))sol(n, arr)t -= 1