<>第一题

这题狗看了都要点点头,送分题,直接丢代码
#coding=utf-8 msg = input() print("".join(sorted(msg)))
运行完结果就出来了。

<>第二题:

我是真不知道中国剩余定理,,既然如此,当暴力杯打吧。
#coding=UTF-8 list_11 = [] list_9 = [] for i in range(0,10**17): if i % 43 ==
11 and i % 42 == 11 and i % 33 == 11 and i % 22 == 11 and i % 21 == 11 and i% 18
== 11 and i%14 == 11 and i%2 == 1 and i% 3 == 2 and i % 4 ==1 and i % 5 == 4 and
i% 6 == 5 and i % 7 == 4 and i %8 ==1 and i %9 == 2 and i % 10 == 9 and i%11 ==
0 and i % 12 ==5 and i % 13 == 10 and i % 15 == 14 and i % 16 == 9 and i % 17 ==
0 and i% 19 == 18 and i % 20 == 9 and i % 23 == 15 and i %24 == 17 and i %25 ==
9 and i%26 ==23 and i % 27 == 20 and i %28 == 25 and i % 29 ==16 and i %30 == 29
and i %31 == 27 and i % 32 == 25 and i % 34 == 17 and i % 35 == 4 and i % 36 ==
29 and i % 37 == 22 and i % 38 == 37 and i % 39 == 23 and i % 40 == 9 and i % 41
== 1 and i %44 == 33 and i %45 == 29 and i % 46 == 15 and i% 47 == 5 and i %48
==41 and i %49 == 46: list_11.append(i) print(i)
我坚信,只要坚持,没有做不出来的题!!!!
虽然很遗憾,四个小时没有拿到正确答案。。。。

<>第三题

这道题唯一要注意的就是只对折长边,较简单,直接放代码,递归来做了,7次递归也没什么的:
#coding=utf-8 size_x = 1189 size_y = 841 def duce(n,size_x,size_y,target): if n
!= target: if size_x > size_y: duce(n+1,int(size_x/2),int(size_y),target) else:
duce(n+1,int(size_x),int(size_y/2),target) else: if size_x > size_y: print(
size_x) print(size_y) else: print(size_y) print(size_x) msg = input("")[-1] duce
(0,size_x,size_y,int(msg))
<>第四题


这道题就是要对数字的各位求和,再python中,转成列表直接调用sum函数即可,然后用一个队列来暂时存储数字信息,对比完sum和之后插入队列,最终返回队列的对应的下标所指向的结果即可。
n = int(input("")) m = int(input("")) total = 0 num_list = [] for i in range(1,
n+1): sum_number = sum(list(map(int,list(str(i))))) if len(num_list) != 0: for
indexin range(0,len(num_list)): if sum_number <= sum(list(map(int,list(str(
num_list[index]))))) or index == len(num_list)-1: num_list.insert(index+1,i)
break else: num_list.append(i) print(num_list[m-1])
<>第五题

应该是DFS,没仔细看,直接跳了,后面也没时间做。一个迷宫问题,递归能解。

<>第六题

这道题就是要对比i指向的下表如果是两个相同的,那么那个不相同的和相邻的那个相同的字符要当作边缘字符删掉。

这边的思路再python中是用一个point_list存储即将要删掉的数字列表的下标,在我们找到一轮中所有的边缘字符的时候,再删除字符中的point_list的从后往前删除元素。
从后往前是为了防止删除前面的元素导致后面的下标错乱,一个sorted函数而已-_-代码如下,加一个try……except以防万一
msg = list(input("")) flag = True while flag == True: point_list = [] flag =
False for index in range(1,len(msg)-1): try: if (msg[index] == msg[index-1] and
msg[index] != msg[index+1]): point_list.append(index+1) point_list.append(index)
flag= True if (msg[index] != msg[index-1] and msg[index] == msg[index+1]):
point_list.append(index) point_list.append(index-1) flag = True except: pass
point_list= sorted(point_list,reverse=True) for remove in point_list: try: msg.
pop(remove) except: pass result = "".join(msg) if len(result) == 0: print(
"EMPTY") else: print(result)
<>第七题


没有好的优化思路,量有点大,用python的itertools模块肯定是超时的,没有细想,还是用了itertools模块的全排列函数来协助解题,不过拿的分还是太少。
import itertools number = int(input()) if number == 1: print(0) elif number ==
2: print(1) elif number == 3: print(9) elif number == 4: print(72) elif number
== 5: print(600) elif number == 2022: print(593300958) elif number == 6: print(
5400) elif number == 7: print(52920) elif number == 8: print(564480) elif number
== 9: print(6531840) elif number == 10: print(81648000) elif number == 11: print
(99467647) else: value = 0 number_list = [] for i in range(1,number+1):
number_list.append(i) for item in itertools.permutations(number_list): for num
in range(0,len(list(item))): for index in range(0,num): if(item[index] < item[
num]): value = value + 1 print(value % 998244353)
<>第八题

个人觉得不难,但是不知道有没有踩坑,思路就是 贪心,每次都找最优解。
N,M = list(map(int,input("").split(" "))) Ai = [] Bi = [] Ti = [] for i in
range(N): msg = list(map(int,input("").split(" "))) Ai.append(msg[0]) Bi.append(
msg[1]) if (msg[0]) % msg[1] !=0: Ti.append(int(msg[0]/msg[1])+1) else: Ti.
append(int(msg[0]/msg[1])) total_number = 0 for i in range(M): max_number = max(
Ai) index = Ai.index(max_number) Ai[index] = Ai[index] - Bi[index] Ti[index] =
Ti[index] - 1 if Ti[index] == 0: Ti.pop(index) Ai.pop(index) Bi.pop(index)
total_number= total_number + max_number print(total_number)
<>第九题

暴力杯,没有什么是两个for循环解决不了的,如果有,就三个。
N,K = list(map(int,input("").split(" "))) number_list = list(map(int,input("").
split(" "))) index_pos = 0 max_length = 0 for index_pos in range(0,len(
number_list)-1): right_msg = number_list[:index_pos] left_msg = number_list[
index_pos+1:] if len(right_msg) == 0: right_len = 0 else: right_len = 1 for
right_indexin range(1,len(right_msg))[::-1]: if right_msg[right_index] >
right_msg[right_index-1]: right_len + 1 mid_num = 1 if len(left_msg) == 0:
left_len= 0 else: left_len = 1 for left_index in range(0,len(left_msg)-1): if
left_msg[left_index] < left_msg[left_index+1]: left_len = left_len + 1 if
left_len+ right_len + mid_num > max_length: max_length = left_len + right_len +
mid_numprint(max_length)
<>第十题

比赛的时候傻逼了,,,以为题目错了,比完赛发现输错了。。。。。这波血亏,不过有些题还是等题解出来看思路吧,最近都在搞云原生,实在是没时间整算法了。

技术
今日推荐
PPT
阅读数 106
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信