how to

教学计划-找规律

Sep 21, 2024
notesjulyfun工作william240921
2 Minutes
377 Words

Problem 3. Spaced Out

https://usaco.org/index.php?page=viewproblem2&cpid=1088

从小规模数据开始绘制,发现要么第一行确定后,每一行与上一行相反。要么第一列确定后,每一行与上一行相反。证明:首先考虑第一行存在连续的 11 或者 00 情况

我们用 f[j][0] 表示第一行第 j 列为 0 时,整个第 j 列的收益,f[j][1] 相反。

1
n = int(input())
2
f = [[0, 0] for _ in range(n)]
3
v = [[0, 0] for _ in range(n)]
4
for i in range(n):
5
s = list(map(int, input().split()))
6
for j, x in enumerate(s):
7
f[j][(i + 1) % 2] += x
8
v[i][(j + 1) % 2] += x
9
10
ans1 = 0
11
for x, y in f:
12
ans1 += max(x, y)
13
ans2 = 0
14
for x, y in v:
15
ans2 += max(x, y)
1 collapsed line
16
print(max(ans1, ans2))

程序填空:

1
n = int(input())
2
f = [[0, 0] for _ in range(n)]
3
v = [[0, 0] for _ in range(n)]
4
for i in range(n):
5
s = list(map(int, input().split()))
6
for j, x in enumerate(s):
7
f[___][___] += x
8
v[___][___] += x
9
10
ans1 = 0
11
for x, y in f:
12
ans1 += __
13
ans2 = 0
14
for x, y in v:
15
ans2 += ___
1 collapsed line
16
print(max(ans1, ans2))

Problem 3. Moo Route

大胆猜测如果能不改方向就不改。往右走如果遇到剩余次数为 0 就掉头。往左走如果左边剩余次数 <= 2 且右边还有可以走的就掉头。否则就回不来了。

1
n = int(input())
2
a = list(map(int, input().split())) + [0]
3
s = sum(a)
4
p = 0
5
d = 1
6
for _ in range(s):
7
if (d == 1 and a[p] == 0) or (d == -1 and a[p - 1] <= 2 and a[p] > 0):
8
d = -d
9
if d == 1:
10
print("R", end='')
11
a[p] -= 1
12
else:
13
print("L", end='')
14
a[p - 1] -= 1
15
p += d

读题 + 思考

USACO 2022 December Contest, Silver

Problem 2. Circular Barn

https://usaco.org/index.php?page=viewproblem2&cpid=1255

Article title:教学计划-找规律
Article author:Julyfun
Release time:Sep 21, 2024
Copyright 2025
Sitemap