本站在允许 JavaScript 运行的环境下浏览效果更佳


Hrbust ACM练习 2024级第5周题单 题解分享

16

相关文章链接

本文还在施工中

宣传:24级计算机学院学习交流群

QQ群号:902195227

前言

题单链接:2024级第5周题单 - Virtual Judge (vjudge.net)

A 题

原题链接:ABC 339C

Python Code

from itertools import accumulate

input()
min_number = 0
last_number = 0

for n in accumulate(map(int, input().split())):
    if n < min_number:
        min_number = n
    last_number = n

if min_number < 0:
    min_number = -min_number
    print(min_number + last_number)
else:
    print(last_number)

B 题

原题链接:P3397

Python Code

from itertools import accumulate


n, m = map(int, input().split())
l = []
for _m in range(n):
    l.append([])
    for _ in range(n + 1):
        l[_m].append(0)

while m > 0:
    m -= 1
    x1, y1, x2, y2 = map(int, input().split())
    for x in range(x1 - 1, x2):
        l[x][y1 - 1] += 1
        l[x][y2] -= 1

for sl in l:
    print(*list(accumulate(sl[:-1])))

C 题

Python Code


D 题

Python Code


E 题

Python Code


F 题

Python Code


G 题

原题链接:ABC 014C

Python Code

from itertools import accumulate

n = int(input())
l = [0] * (1000000 + 2)
while n > 0:
    n -= 1
    a, b = map(int, input().split())
    l[a] += 1
    l[b + 1] -= 1
print(max(accumulate(l)))

H 题

原题链接:ABC 035C

试了一下 AtCoder,这个判题机是很奇葩的。之前用 print(rt, end="") 会 WA。看了别人的博客才知道这个网站的老题有 bug,在程序输出结束后不进行换行是会 WA 的。新题目已修复。

from itertools import accumulate


n, q = map(int, input().split())
l = []
for _ in range(0, n + 2):
    l.append(1)

while q > 0:
    q -= 1
    li, ri = map(int, input().split())
    l[li - 1] *= -1
    l[ri] *= -1
_n = 0
last_one = 0
rt = ""
for i in range(0, n):
    if _n == n:
        break
    if l[i] == -1:  # 和前一个不一样
        if i == 0 or last_one == 0:
            last_one = 1
        else:
            last_one = 0
        rt += str(last_one)
    else:  # 和前一个一样
        rt += str(last_one)
    _n += 1
print(rt)