Skip to content

教学计划 找规律

Problem 3. Spaced Out

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

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

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

n = int(input())
f = [[0, 0] for _ in range(n)]
v = [[0, 0] for _ in range(n)]
for i in range(n):
    s = list(map(int, input().split()))
    for j, x in enumerate(s):
        f[j][(i + 1) % 2] += x
        v[i][(j + 1) % 2] += x

ans1 = 0
for x, y in f:
    ans1 += max(x, y)
ans2 = 0
for x, y in v:
    ans2 += max(x, y)
print(max(ans1, ans2))

程序填空:

n = int(input())
f = [[0, 0] for _ in range(n)]
v = [[0, 0] for _ in range(n)]
for i in range(n):
    s = list(map(int, input().split()))
    for j, x in enumerate(s):
        f[___][___] += x
        v[___][___] += x

ans1 = 0
for x, y in f:
    ans1 += __
ans2 = 0
for x, y in v:
    ans2 += ___
print(max(ans1, ans2))

Problem 3. Moo Route

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

n = int(input())
a = list(map(int, input().split())) + [0]
s = sum(a)
p = 0
d = 1
for _ in range(s):
    if (d == 1 and a[p] == 0) or (d == -1 and a[p - 1] <= 2 and a[p] > 0):
        d = -d
    if d == 1:
        print("R", end='')
        a[p] -= 1
    else:
        print("L", end='')
        a[p - 1] -= 1
    p += d

读题 + 思考

USACO 2022 December Contest, Silver

Problem 2. Circular Barn

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