[toc]

A 排列字母

我的题解

签到题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import os
import sys

s = input()
arr = [0]*100

for i in range(len(s)):
arr[ord(s[i]) - ord('A')] +=1


for i in range(0,26):
#print(arr[i],end=" ")
if arr[i] != 0:
for _ in range(arr[i]):
print(chr(i+ord('A')),end='')


正确题解

1
2
string = 'WHERETHEREISAWILLTHEREISAWAY'
print(''.join(sorted(string)))

B 寻找整数

正确题解

参考题解0寻找整数 - 蓝桥云课

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
L=[]
for i in range(187,10**12,187):
if i%44==33 and i%45==29 and i%46==15 and i%47==5 and i%48==41 and i%49==46:
#else:
L.append(i)
if len(L)>=2:
break
arr = [0,0,1,2,1,4,5,4,1,2,9,0,5,10,
11,14,9,0,11,18,9,11,11,15,17,9,
23,20,25,16,29,27,25,11,17,4,29,22,
37,23,9,1,11,11,33,29,15,5,41,46]


print(L)
L=[5458460249, 12590206409]
step=L[1]-L[0]
flag=0
for i in range(L[0],10**17,step):
flag = False
for j in range(2,50):
if i%j!=arr[j]:
flag =True
continue
if flag == False:
print(i)
break

C 纸张尺寸

我的题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43


x = 1189
y = 841

arr1 = [1189,841,594,420,297,210,148,105,74,52,37,26,18]
arr2 = [841,594,420,297,210,148,105,74,52,37,26,18,13]


def cal(a,b,n):
if n>=20:
exit(0)
print(f'{a} {b}')
cal(b,a//2,n+1)

s = input()
pos = int(s[1])
# print(pos)
print(arr1[pos])
print(arr2[pos])


##1189 841
##841 594
##594 420
##420 297
##297 210
##210 148
##148 105
##105 74
##74 52
##52 37
##37 26
##26 18
##18 13
##13 9
##9 6
##6 4
##4 3
##3 2
##2 1
##1 1

D 数位排序

我的题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import sys
from functools import cmp_to_key

class Node:
def __init__(self,v,pos):
self.v = v
self.pos = pos
def __repr__(self):
return repr((self.v,self,pos))

n = int(input())
m = int(input())

li = []


def ini(x):
sum = 0
while x//10 !=0:
sum+=x%10
x//=10
return sum+x
def cmp(x,y):
if x.pos == y.pos:
return x.v - y.v
return x.pos - y.pos



for i in range(1,n):
li.append(Node(i,ini(i)))


li.sort(key = cmp_to_key(cmp))

##for i in li:
## print(f'{i.v} {i.pos}')
print(li[m-1].v)



正确题解

1
2
3
4
5
6
7
8
import os
import sys

n=int(input())
m=int(input())
s=list(range(1,n+1))
s.sort(key=lambda x:sum(int(i) for i in str(x)))
print(s[m-1])

E 蜂巢

其实这题不是很难,要对自己有信心

正确题解

  • 将六边形转化为直角坐标系,然后进行坐标计算

  • a到b点,考虑斜着走和先斜着走,在横着走的操作z

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import sys

# 请在此输入您的代码
d1,p1,q1,d2,p2,q2=map(int,input().split())

xway = [-1,-0.5,0.5,1,0.5,-0.5]
yway = [0,1,1,0,-1,-1]

xa = xway[d1]*p1 + xway[(d1+2)%6]*q1
ya = yway[d1]*p1 + yway[(d1+2)%6]*q1

xb = xway[d2]*p2 + xway[(d2+2)%6]*q2
yb = yway[d2]*p2 + yway[(d2+2)%6]*q2

disx = abs(xa-xb)
disy = abs(ya-yb)


if disx < disy/2: #斜着走就能到
print(int(disy))
else:
disx -= disy*0.5
print(int(disy+disx))

F 消除游戏

TODO

我的题解

1
print("EMPTY")

正确题解

0全排列的价值 - 蓝桥云课

G 全排列

我的题解

想着dfs枚举推公式,然后推不出来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36


st = [False] * 10
n = 3
ans =[]

def judge():
cnt = 0
for i in range (1,len(path)):
for j in range(0,i):
if path[i] > path[j]:
cnt += 1
res.append(cnt)
def dfs(u):
if u==n:
# print(path)
judge()
return
for v in range(1,n+1):
if st[v] == False:
st[v] = True
path.append(v)
dfs(u+1)
path.pop()
st[v] = False

for i in range(3,6):
res = []
n = i
path = []
dfs(0)
ans.append(sum(res))



print(ans)

正确解法

H

线段树,跳过

J 最优清零方案

我的题解

通过枚举每个n//k个区间,减去最小值,加上剩余得单独处理的元素。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
sys.setrecursionlimit(50000)
input = lambda: sys.stdin.readline().strip()

n, k = map(int,input().split())
arr = list(map(int,input().split()))

cnt = n//k
res = 0
# print(cnt)
for i in range(cnt):
tmp = i * k
#print(tmp)
cntt = 0
minnum = 100000000
for j in range(tmp,tmp+k):
cntt += arr[j]
minnum = min(arr[j],minnum)
## print(f'{cntt} {minnum}')

res += cntt-minnum*(k-1)

#print(cnt*k)
for j in range(cnt*k,n):
res += arr[j]




print(res)

正确题解

  • 果然还是不够贪啊

  • 每次操作选择连续的 k 个元素,减去它们的最小值 min_val,操作次数加 min_val

  • 剩余不足 k 的元素逐个减(操作次数加剩余元素的和)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import sys

n,k = map(int,input().split())

nums = list(map(int,input().split()))

cnt = 0

i = 0
while i < n-k+1:
x = min(nums[i:i+k])
b = nums[i:i+k].index(x) #最小值下标,减去后为0
if x:
for a in range(i,i+k):
nums[a] -= x
cnt+=x
i+=b+1 #最小值下标为0,+1
print(cnt+sum(nums))