s='WHERETHEREISAWILLTHEREISAWAY'
s=list(s)
s.sort()
print(''.join(s))
#AAAEEEEEEHHHIIILLRRRSSTTWWWY
答案:2022040920220409
思路:中国剩余定理应该能做,不过比赛的时候记不清咋写的了,就暴力一波。注意,一个个累加是不行的,自己用python算一下pow(10,17)就知道了。我当时选了最后五个数,因为这几个比较大,先找到能同时满足这五个的数的规律:
tmp.py
i=1
while True:
flag=True
if i%49!=46:
flag=False
if i%48!=41:
flag=False
if i%47!=5:
flag=False
if i%46!=15:
flag=False
if i%45!=29:
flag=False
if flag:
print(i)
i+=1
跑出来前几个就够了:4772009, 42909689, 81047369, 119185049,157322729, 195460409, 233598089……不用说肯定是等差数列,再稍微验证一下y=38137680*x+4772009
然后枚举那个x的值,再遍历前面的是否满足即可,这样就能跑出来:
B.py
mod = [(2, 1), (14, 11), (26, 23), (38, 37),
(3, 2), (15, 14), (27, 20), (39, 23),
(4, 1), (16, 9), (28, 25), (40, 9),
(5, 4), (17, 0), (29, 16), (41, 1),
(6, 5), (18, 11), (30, 29), (42, 11),
(7, 4), (19, 18), (31, 27), (43, 11),
(8, 1), (20, 9), (32, 25), (44, 33),
(9, 2), (21, 11), (33, 11), (45, 29),
(10, 9), (22, 11), (34, 17), (46, 15),
(11, 0), (23, 15), (35, 4), (47, 5),
(12, 5), (24, 17), (36, 29), (48, 41),
(13, 10), (25, 9), (37, 22)]
i = 0
cha = 38137680
while True:
flag = True
num = cha*i+4772009
for x, y in mod:
if num % x != y:
flag = False
break
if flag:
print(num)
break
i += 1
# 2022040920220409
没啥好说的,长边整除2即可
name = input()
A0x, A0y = 1189, 841
if name == 'A0':
print(A0x)
print(A0y)
else:
cnt = int(name[1])
for i in range(cnt):
A0x, A0y = A0y, A0x//2
print(A0x)
print(A0y)
只要会用cmp_to_key就不难
from functools import cmp_to_key
def cmp(x, y):
hx = getHe(x)
hy = getHe(y)
if hx == hy:
return x-y
return hx-hy
def getHe(n):
res = 0
while n > 0:
res += n % 10
n //= 10
return res
n = int(input())
m = int(input())
num = [i for i in range(1, n+1)]
num.sort(key=cmp_to_key(cmp))
print(num[m-1])
没思路
s = list(input())
pre = s
f = False
for i in range(pow(2, 64)):
flag = [False]*len(s)
for j in range(1, len(s)-1):
if s[j] == s[j-1] and s[j] != s[j+1]:
flag[j] = True
flag[j+1] = True
if s[j] != s[j-1] and s[j] == s[j+1]:
flag[j-1] = True
flag[j] = True
for j in range(len(flag)):
if flag[j]:
s[j] = ''
s = list(''.join(s))
if len(s) == 0:
f = True
break
if pre == s:
break
pre = s
if f:
print('EMPTY')
else:
print(''.join(s))
写了一点,就不放出来丢人了
求最大值那边应该可以用大顶堆优化一下,时间复杂度可以降到nlogn,比赛时忘了优化,呜呜呜
from math import ceil
n, m = map(int, input().split())
a = [0]
b = [0]
dp = [0]*(m+1)
for i in range(n):
x, y = map(int, input().split())
a.append(x)
b.append(y)
for j in range(1, m+1):
index = 0
for k in range(1, n+1):
if a[k] > a[index]:
index = k
dp[j] = dp[j-1]+a[index]
a[index] -= b[index]
a[index] = max(a[index], 0)
print(dp[m])