蓝桥·算法赛——第10场

小白入门赛

1-五一礼物

2-合成贤者之石

3-Yaya与加减法

from queue import PriorityQueue

n, A, B = map(int, input().split())
a = list(map(int, input().split()))
Q1 = PriorityQueue() # 负数
Q2 = PriorityQueue() # 正数
s = a[0]; cnt = 0

for i in range(1, n):
    s += a[i] # 求和
    if a[i] < 0: # 统计负数个数(第一位除外)
        cnt += 1; Q1.put(a[i])
    else:
        Q2.put(a[i])

if B >= cnt: # 理论上负号数为cnt
    if n - 1 - cnt > A: # 正号个数不够 实际负号个数为n - 1 - A(更多)
        for i in range(cnt):
            x = Q1.get(); s += 2 * (-x)
        for i in range(n - 1 - A - cnt):
            x = Q2.get(); s -= 2 * x
    else: # 正号个数够
        for i in range(cnt):
            x = Q1.get(); s += 2 * (-x)
else: # 理论上负号数为B
    for i in range(B):
        x = Q1.get(); s += 2 * (-x)

print(s)

4-Yaya与字符画

n, m = map(int, input().split())
maze = [input() for _ in range(n)]
ans = 0

for i in range(n - 1, 0, -1): # 不取第一行
    for j in range(1, m - 1): # 不取第一列和最后一列
        if maze[i][j] == '*': # 检查V的大小
            # k的取值范围[1, min(j, m - j - 1, i)]
            base = min(j, m - j - 1, i)
            if base <= ans: continue # 剪枝
            for k in range(1, base + 1):
                if maze[i - k][j - k] == '*' and maze[i - k][j + k] == '*':
                    ans = max(ans, k)
                else: # 提前剪枝
                    break
print(ans)

5-咒语融合

def check(num1, num2):
    num = 0
    while num1 > 0 and num2 > 0:
        if num1 % 10 == num2 % 10:
            num += num1 % 10
        num1 //= 10; num2 //= 10
    return num

n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in range(n - 1, 0, -1):
    if a[i] + a[0] <= ans: break  # 剪枝
    for j in range(i - 1, -1, -1):
        if a[i] + a[j] <= ans: continue  # 剪枝
        cnt = a[i] + a[j] - check(a[i], a[j])
        ans = max(ans, cnt)
print(ans)     

6-Yaya与游戏

from bisect import bisect_left, insort
from copy import deepcopy

def check(nums, Len, num):
    # 判断 nums 能否凑出 1 ~ num
    lst = deepcopy(nums)
    for i in range(num, 0, -1):
        idx = bisect_left(lst, i)
        if idx == Len: # 凑不出来
            return False
        re = lst[idx] - i; lst.pop(idx)
        if re > 0: insort(lst, re)
        else: Len -= 1 # 不插入
    return True

def calc(nums, Len): # 二分模板
    l = 1; r = 10 ** 6
    while l <= r:
        mid = (l + r) >> 1
        if check(nums, Len, mid):
            l = mid + 1
        else:
            r = mid - 1
    return r

n, X = map(int, input().split())
a = [X] + list(map(int, input().split()))
a.sort(); ans1 = calc(a, n + 1) # a能凑到连续的最大数

m, Y = map(int, input().split())
b = [Y] + list(map(int, input().split()))
b.sort(); ans2 = calc(b, m + 1) # b能凑到连续的最大数

if ans1 > ans2:
    print("Clrlss")
elif ans1 < ans2:
    print("Yaya")
else:
    print("Draw")

强者挑战赛

1-Yaya与加减法

from queue import PriorityQueue

n, A, B = map(int, input().split())
a = list(map(int, input().split()))
Q1 = PriorityQueue() # 负数
Q2 = PriorityQueue() # 正数
s = a[0]; cnt = 0

for i in range(1, n):
    s += a[i] # 求和
    if a[i] < 0: # 统计负数个数(第一位除外)
        cnt += 1; Q1.put(a[i])
    else:
        Q2.put(a[i])

if B >= cnt: # 理论上负号数为cnt
    if n - 1 - cnt > A: # 正号个数不够 实际负号个数为n - 1 - A(更多)
        for i in range(cnt):
            x = Q1.get(); s += 2 * (-x)
        for i in range(n - 1 - A - cnt):
            x = Q2.get(); s -= 2 * x
    else: # 正号个数够
        for i in range(cnt):
            x = Q1.get(); s += 2 * (-x)
else: # 理论上负号数为B
    for i in range(B):
        x = Q1.get(); s += 2 * (-x)

print(s)

2-Yaya与字符画

n, m = map(int, input().split())
maze = [input() for _ in range(n)]
ans = 0

for i in range(n - 1, 0, -1): # 不取第一行
    for j in range(1, m - 1): # 不取第一列和最后一列
        if maze[i][j] == '*': # 检查V的大小
            # k的取值范围[1, min(j, m - j - 1, i)]
            base = min(j, m - j - 1, i)
            if base <= ans: continue # 剪枝
            for k in range(1, base + 1):
                if maze[i - k][j - k] == '*' and maze[i - k][j + k] == '*':
                    ans = max(ans, k)
                else: # 提前剪枝
                    break
print(ans)

3-Yaya与游戏

from bisect import bisect_left, insort
from copy import deepcopy

def check(nums, Len, num):
    # 判断 nums 能否凑出 1 ~ num
    lst = deepcopy(nums)
    for i in range(num, 0, -1):
        idx = bisect_left(lst, i)
        if idx == Len: # 凑不出来
            return False
        re = lst[idx] - i; lst.pop(idx)
        if re > 0: insort(lst, re)
        else: Len -= 1 # 不插入
    return True

def calc(nums, Len): # 二分模板
    l = 1; r = 10 ** 6
    while l <= r:
        mid = (l + r) >> 1
        if check(nums, Len, mid):
            l = mid + 1
        else:
            r = mid - 1
    return r

n, X = map(int, input().split())
a = [X] + list(map(int, input().split()))
a.sort(); ans1 = calc(a, n + 1) # a能凑到连续的最大数

m, Y = map(int, input().split())
b = [Y] + list(map(int, input().split()))
b.sort(); ans2 = calc(b, m + 1) # b能凑到连续的最大数

if ans1 > ans2:
    print("Clrlss")
elif ans1 < ans2:
    print("Yaya")
else:
    print("Draw")

4-Yaya与区间

5-Yaya与排列

6-Yaya与数数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胆怯与勇敢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值