蓝桥·算法赛——第11场

小白入门赛

1-国际博物馆日

2-最小值取余

3-小蓝方程

4-玩偶购买

T = int(input())
for _ in range(T):
    n, x, y, a, b = map(int, input().split())
    cnt = n // y; cnt1 = a // x; cnt2 = b // x
    if cnt == 0 or cnt2 == 0:
        print(-1)
    elif cnt <= cnt2:
        print(cnt)
    else:
        print(cnt2 + min(cnt2 - 1, cnt1, cnt - cnt2))

5-数学魔术家

x = list(input())
print("".join(sorted(x, reverse=True)), end=" ")
num = '9'; idx = -1
for i, data in enumerate(x):
    if data != '0' and data <= num:
        num = data; idx = i
new = x[: idx] + x[idx + 1:]
new.sort()
print(num + "".join(new))

6-矿石样本分析

n, K = map(int, input().split())
a = [0] + list(map(int, input().split()))
dic = {}; ans = n
for i in range(1, n + 1):
    if a[i] * 2 != K and K - a[i] in dic:
        times = max(dic.get(K - a[i]), min(i, n - i + 1))
        ans = min(ans, times)
    dic[a[i]] = min(dic.get(a[i], n), min(i, n - i + 1))
print(ans if ans != n else -1)

强者挑战赛

1-玩偶购买

T = int(input())
for _ in range(T):
    n, x, y, a, b = map(int, input().split())
    cnt = n // y; cnt1 = a // x; cnt2 = b // x
    if cnt == 0 or cnt2 == 0:
        print(-1)
    elif cnt <= cnt2:
        print(cnt)
    else:
        print(cnt2 + min(cnt2 - 1, cnt1, cnt - cnt2))

2-数学魔术家

x = list(input())
print("".join(sorted(x, reverse=True)), end=" ")
num = '9'; idx = -1
for i, data in enumerate(x):
    if data != '0' and data <= num:
        num = data; idx = i
new = x[: idx] + x[idx + 1:]
new.sort()
print(num + "".join(new))

3-矿石样本分析

n, K = map(int, input().split())
a = [0] + list(map(int, input().split()))
dic = {}; ans = n
for i in range(1, n + 1):
    if a[i] * 2 != K and K - a[i] in dic:
        times = max(dic.get(K - a[i]), min(i, n - i + 1))
        ans = min(ans, times)
    dic[a[i]] = min(dic.get(a[i], n), min(i, n - i + 1))
print(ans if ans != n else -1)

4-拔苗助长

N = 1000005; prime = [True] * N
prime[0] = prime[1] = False
lst1 = list()
for i in range(2, N):
    if prime[i]:
        lst1.append(i)
        for j in range(i * 2, N, i):
            prime[j] = False

dic2 = {}
for i in range(1, 1001):
    dic2[i * i] = 1

def check(num):
    dic = {}; i = 0; cnt = 0
    while num != 1:
        while num % lst1[i] == 0:
            num //= lst1[i]
            dic[lst1[i]] = dic.get(lst1[i], 0) + 1
        cnt += dic.get(lst1[i], 0) % 2
        i += 1
    return cnt

N = int(input()); ans = 0
h = list(map(int, input().split()))
for i in range(N):
    if h[i] in dic2:
        continue
    if prime[h[i]]:
        ans += 1; continue
    ans += check(h[i])
print(ans)

5-皇家守卫

6-分子实验

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

胆怯与勇敢

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

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

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

打赏作者

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

抵扣说明:

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

余额充值