洛谷题单,蓝桥备赛
题单链接
未完待续… 预计 2025年2月26日 前完成
目录
- 进度
- 题解与碎碎念
-
- P1042 [NOIP 2003 普及组] 乒乓球
- P2670 [NOIP 2015 普及组] 扫雷游戏
- P1563 [NOIP 2016 提高组] 玩具谜题
- P1601 A+B Problem(高精度)
- P1303 A*B Problem(高精度)
- P1009 阶乘之和
- P4924 [1007] 魔法少女小Scarlet
- P1328 [NOIP 2014 提高组] 生活大爆炸版石头剪刀布
- P1518 [USACO2.4] 两只塔姆沃斯牛 The Tamworth Two
- P1067 多项式输出
- P1098 [NOIP 2007 提高组] 字符串的展开
- P1591 阶乘数码
- P1065 [NOIP 2006 提高组] 作业调度方案
- P1249 最大乘积
- P1786 帮贡排序
- P1045 [NOIP 2003 普及组] 麦森数
- 完结撒花🎉
进度
【2025年2月19日19点33分】写了前俩,歇了
【2025年2月21日】写了俩,太 ez
【2025年2月22日18点51分】写了四,太 ez
【2025年2月23日】1道
【2025年2月24日】开学快乐🐱
【2025年2月25日】听说要在明天前写完【18点09分,记】啊啊啊还有两题今天晚上一定要写完,要争气啊(最近刷题蛮热心,SCI是一点没搞啊)
题解与碎碎念
P1042 [NOIP 2003 普及组] 乒乓球
题面
小结
- 读入处理的一般(蒟蒻刚从C++转python,见谅)
- 输出处理的很
冗余丑陋(勉强能满足输出条件) - 为什么一定要匹配
W L E
,用else
死了一半
槽点/易错点:
- 最后一个数据点,在匹配E,
0:0
也是要输出的,亏我多虑卡 90(我恨 - 考虑只有
E
的情况 - (可能需要考虑)没有E,用字符串末尾控制结束,我用的是把
input_data
的\n
都替换成空,数它的length
ac代码
import sys
input_data = sys.stdin.read()
input_data = input_data.replace("\n", "")
def WorL(n):
Wcount, Lcount = 0, 0
head = 1
length = len(input_data)
# print(f"length= {length}")
for index, char in enumerate(input_data):
# print(f'idx= {index}')
# print(char)
if char == "E":
if head == 1:
print(f"{
Wcount}:{
Lcount}", end="")
else:
# 槽点1,意思是这里不用判断是不是0:0从而不输出
print(f"\n{
Wcount}:{
Lcount}", end="")
break
elif char == "W":
Wcount += 1
elif char == "L":
Lcount += 1
if index == length - 1:
if head == 1:
print(f"{
Wcount}:{
Lcount}", end="")
else:
if not(Wcount == 0 and Lcount == 0):
print(f"\n{
Wcount}:{
Lcount}", end="")
break
if max(Wcount, Lcount) >= n and abs(Wcount - Lcount) >= 2:
if head == 1:
print(f"{
Wcount}:{
Lcount}", end="")
head = 0
else:
print(f"\n{
Wcount}:{
Lcount}", end="")
Wcount, Lcount = 0, 0
WorL(11)
print("\n")
WorL(21)
P2670 [NOIP 2015 普及组] 扫雷游戏
题面
小结
ez(就是python不熟悉,写的有点累
ac代码
import sys
firstLine = sys.stdin.readline().strip()
N, M = map(int, firstLine.split())
mineFiled = []
for _ in range(N):
line = sys.stdin.readline().strip()
mineFiled.append(line)
for i in range(N):
mineFiled[i] = '?' + mineFiled[i] + '?'
addRow = '?' * (M + 2)
mineFiled.insert(0, addRow)
mineFiled.append(addRow)
ans = [[0] * M for _ in range(N)]
def sumRegion(I, J, matrix):
# print(matrix)
sum = 0
for i in range(I - 1, I + 2):
for j in range(J - 1, J + 2):
# print(f'i= {i}, j= {j}')
if matrix[i][j] == '?':
sum += 1
return 9 - sum
for i in range(1, N + 1):
# print(mineFiled[i])
for j in range(1, M + 1):
if mineFiled[i][j] == '?':
# print(f'__i= {i}, j= {j}')
ans[i - 1][j - 1] = sumRegion(i, j, mineFiled)
else:
ans[i - 1][j - 1] = -1
# print(ans)
for i in range(0, N):
for j in range(0, M):
if ans[i][j] == 0-1:
print("*", end="")
else:
print(ans[i][j], end="")
print("")
P1563 [NOIP 2016 提高组] 玩具谜题
题面
略(太 ez 了)
小结
太 ez,模拟一下就好了
ac代码
import sys
def reCount(current, face, l0r1, allC, count):
if face == 0: # face inter
if l0r1 == 0: # 左数
current = (current + allC - count) % allC
else:
current = (current + count) % allC
else:
if l0r1 == 1:
current = (current + allC - count) % allC
else:
current = (current + count) % allC
return current
firstLine = sys.stdin.readline().strip()
N, M = map(int, firstLine.split())
bots = []
for i in range(N):
line = sys.stdin.readline().strip()
parts = line.split()
data = (int(parts[0]), parts[1])
bots.append(data)
# print(bots)
current = 0
rules = []
for i in range(M):
line = sys.stdin.readline().strip()
# print(line)
parts = line.split()
parts = [int(parts[0]), int(parts[1])]
rules.append(parts)
for i in range(M):
# # def reCount(current, face, l0r1, allC, count):
current = reCount(current, bots[current][0],
rules[i][0], N, rules[i][1])
print(f"{
bots[current][1]}")
P1601 A+B Problem(高精度)
题面
就是最简单的高精度加法(没有负数)
原题链接
小结
ez,太 ez
才知道python直接支持高精度
“Python的整数类型没有固定的大小限制,它会根据需要动态扩展以存储任意大的整数。”
ac代码
import sys
line1 = sys.stdin.readline().strip()
line2 = sys.stdin.readline().strip()
# line1 = line1[::-1]
# line2 = line2[::-1]
length = max(len(line1), len(line2)) + 1
a = [0] * length
b = [0] * length
abeg = length - len(line1)
for i in range(len(line1)):
a[abeg] = line1[i]
abeg += 1
bbeg = length - len(line2)
for i in range(len(line2)):
b[bbeg] = line2[i]
bbeg += 1
ans = [0] * length
for i in range(length - 1, -1, -1):
ans[i] += int(a[i]) + int(b[i])
if ans[i] > 9:
ans[i - 1] = 1
ans[i] = ans[i] - 10
if ans[0] != 0:
print(ans[0], end="")
for i in range(1, length):
print(ans[i], end="")
P1303 A*B Problem(高精度)
题面
高精度乘法
原题链接
小结
ez,公式 ans[i + j] += (int(a[i]) * int(b[j]))
犯了蠢,沿用了加法的
if ans[i] > 9:
ans[i - 1] = 1
ans[i] = ans[i] - 10
其实是
if ans[i] > 9:
ans[i - 1] += (ans[i] // 10)
ans[i] %= 10
才知道,python直接支持高精度
“Python的整数类型没有固定的大小限制,它会根据需要动态扩展以存储任意大的整数。”
ac代码
import sys
line1 = sys.stdin.readline().strip()
line2 = sys.stdin.readline().strip()
length = max(len(line1), len(line2)) + 1
abeg = length - len(line1)
a =