The 13th Blue Bridge Cup Competition python group B problem solving exchange

first question

insert image description here
The dog has to nod his head when he sees this question, send the sub-question, and directly lose the code

#coding=utf-8
msg = input()
print("".join(sorted(msg)))

After running, the result will come out.

Second question:

insert image description here

I really don't know the Chinese remainder theorem. In that case, let's fight it with violence.

#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)

I firmly believe that as long as you persevere, there is no problem that cannot be solved! ! ! !
Although unfortunately, I didn't get the correct answer for four hours. . . .

Question 3

insert image description here
The only thing to pay attention to in this question is that only the long side is folded in half, which is relatively simple. Just put the code directly, and do it recursively. Seven recursion is nothing:

#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))

Question 4

insert image description here
This problem is to sum the digits of the number, and then in python, convert it into a list and call the sum function directly, and then use a queue to temporarily store the digital information, compare the sum and then insert the queue, and finally return the corresponding value of the queue The result pointed to by the subscript can be used.

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 index in 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])

Question 5

insert image description here
It should be DFS, I skipped it without looking carefully, and I didn't have time to do it later. A maze problem that can be solved recursively.

Question 6

insert image description here
This question is to compare the following table pointed to by i. If the two tables are the same, then the different and adjacent same characters should be deleted as edge characters.
The idea here is to use a point_list to store the subscript of the number list to be deleted in python. When we find all the edge characters in a round, delete the point_list in the character and delete the elements from the back to the front.
From back to front is to prevent the deletion of the previous elements from causing confusion in the following subscripts, a sorted function is just -_- The code is as follows, add a try...except just in case

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)

Question 7

insert image description here
There is no good optimization idea, and the amount is a bit large. Using python's itertools module must be timed out. I didn't think about it carefully. I still used the full arrangement function of the itertools module to assist in solving the problem, but the points were still too few.

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)

Question 8

insert image description here
Personally, I don't think it is difficult, but I don't know if I have stepped on the pit. The idea is greed, and I always find the best solution.

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)

Question 9

insert image description here
Violence Cup, there is nothing that two for loops can't solve, if there is, there are three.

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_index in 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_num
print(max_length)

Question 10

insert image description here
During the competition, I was an idiot. I thought the title was wrong, but after the competition, I found out that I lost the wrong one. . . . . This wave of blood loss, but some problems are still waiting to be solved to see the idea. Recently, I have been working on cloud native, and I really don’t have time to adjust the algorithm.

Guess you like

Origin blog.csdn.net/qq_27180763/article/details/124063734