本文记录一下本人的解题。
前提说明:本人没有学过任何算法,解题仅供参考!
大多数情况下,俺的暴力还是能过一部分数据的,但是数据太大的时候就过不了了,我也没有办法,只能参考某些大佬的优化了。
1、第一题
print(int("AAA",16))
# 答案是2730
2、第二题
这个题目可以直接手算,也可以打开Excel,直接查。我个人选择的后者,答案是:BYT。
3、第三题
import datetime
dat1 = datetime.date(1900,1,1)
dat2 = datetime.date(9999,12,31)
comaaa = 0
def com(yl,year,ml,month,dl,day):
s,y = 0,0
for i in range(yl):
s = s +int(year[i])
for u in range(ml):
y = y + int(month[u])
for x in range(dl):
y = y+ int(day[x])
if s == y:
return True
while dat1 != dat2:
yl,year,ml,month,dl,day = len(str(dat1.year)),str(dat1.year),len(str(dat1.month)),str(dat1.month),len(str(dat1.day)),str(dat1.day)
if com(yl,year,ml,month,dl,day):
comaaa = comaaa+1
dat1 = dat1 + datetime.timedelta(1)
print(comaaa)
暴力直接冲烂它,结果是:70910。
4、第四题
list = [99,22,51,63,72,61,20,88,40,21,63,30,11,18,99,12,93,16,7,53,64,9,28,84,34,96,52,82,51,77]
cons = 0
for i in range(len(list)):
for u in range(i+1, len(list)):
if list[i]*list[u] >= 2022:
cons += 1
print(cons)
答案是:189。
5、第五题
110010000011111110101001001001101010111011011011101001111110
010000000001010001101100000010010110001111100010101100011110
001011101000100011111111111010000010010101010111001000010100
101100001101011101101011011001000110111111010000000110110000
010101100100010000111000100111100110001110111101010011001011
010011011010011110111101111001001001010111110001101000100011
101001011000110100001101011000000110110110100100110111101011
101111000000101000111001100010110000100110001001000101011001
001110111010001011110000001111100001010101001110011010101110
001010101000110001011111001010111111100110000011011111101010
011111100011001110100101001011110011000101011000100111001011
011010001101011110011011111010111110010100101000110111010110
001110000111100100101110001011101010001100010111110111011011
111100001000001100010110101100111001001111100100110000001101
001110010000000111011110000011000010101000111000000110101101
100100011101011111001101001010011111110010111101000010000111
110010100110101100001101111101010011000110101100000110001010
110101101100001110000100010001001010100010110100100001000011
100100000100001101010101001101000101101000000101111110001010
101101011010101000111110110000110100000010011111111100110010
101111000100000100011000010001011111001010010001010110001010
001010001110101010000100010011101001010101101101010111100101
001111110000101100010111111100000100101010000001011101100001
101011110010000010010110000100001010011111100011011000110010
011110010100011101100101111101000001011100001011010001110011
000101000101000010010010110111000010101111001101100110011100
100011100110011111000110011001111100001110110111001001000111
111011000110001000110111011001011110010010010110101000011111
011110011110110110011011001011010000100100101010110000010011
010011110011100101010101111010001001001111101111101110011101
data =[
"110010000011111110101001001001101010111011011011101001111110",
"010000000001010001101100000010010110001111100010101100011110",
"001011101000100011111111111010000010010101010111001000010100",
"101100001101011101101011011001000110111111010000000110110000",
"010101100100010000111000100111100110001110111101010011001011",
"010011011010011110111101111001001001010111110001101000100011",
"101001011000110100001101011000000110110110100100110111101011",
"101111000000101000111001100010110000100110001001000101011001",
"001110111010001011110000001111100001010101001110011010101110",
"001010101000110001011111001010111111100110000011011111101010",
"011111100011001110100101001011110011000101011000100111001011",
"011010001101011110011011111010111110010100101000110111010110",
"001110000111100100101110001011101010001100010111110111011011",
"111100001000001100010110101100111001001111100100110000001101",
"001110010000000111011110000011000010101000111000000110101101",
"100100011101011111001101001010011111110010111101000010000111",
"110010100110101100001101111101010011000110101100000110001010",
"110101101100001110000100010001001010100010110100100001000011",
"100100000100001101010101001101000101101000000101111110001010",
"101101011010101000111110110000110100000010011111111100110010",
"101111000100000100011000010001011111001010010001010110001010",
"001010001110101010000100010011101001010101101101010111100101",
"001111110000101100010111111100000100101010000001011101100001",
"101011110010000010010110000100001010011111100011011000110010",
"011110010100011101100101111101000001011100001011010001110011",
"000101000101000010010010110111000010101111001101100110011100",
"100011100110011111000110011001111100001110110111001001000111",
"111011000110001000110111011001011110010010010110101000011111",
"011110011110110110011011001011010000100100101010110000010011",
"010011110011100101010101111010001001001111101111101110011101"]
def dfs(x, y, num):
vis[x][y] = 1
for dx,dy in [(1, 0), (-1, 0), (0,1), (0, -1)]:
current_x = x + dx
current_y = y + dy
if 0 <= current_x < 30 and 0 <= current_y <60:
try:
if vis[current_x][current_y] != 1 and data[current_x][current_y] == '1':
num = dfs(current_x,current_y,num)
except:
print(current_x)
print(current_y)
return num + 1
res = 0
vis = [[0 for i in range(60)] for j in range(30)]
for i in range(30):
for j in range(60):
if data[i][j] == '1' and vis[i][j] == 0:
num = 0
num = dfs(i,j,num)
res = max(num, res)
print(res)
答案是:148。
6、第六题
n = eval(input())
nm = eval(input())
nm = nm % 7
if n + nm >7:
print((n + nm) % 7)
else:
print(n + nm)
7、第七题
w, h, n, r = map(int, input().split())
points = set()
ans = 0
for _ in range(n):
a, b = map(int, input().split())
points.add((a, b))
def check(x, y):
for a, b in points:
if pow(x - a, 2) + pow(y - b, 2) <= r * r:
return True
return False
for i in range(w + 1):
for j in range(h + 1):
if check(i, j):
ans += 1
print(ans)
8、第八题
ponit = set()
s = set()
n,m = map(int,input().split())
for b in range(n):
for v in range(m):
s.add((b,v))
t = eval(input())
for i in range(t):
r1,c1,r2,c2 = map(int,input().split())
for u in range(r1-1,r2):
for x in range(c1-1,c2):
ponit.add((u,x))
ponit = set(ponit)
result = s - ponit
print(len(result))
9、第九题
# 错误的暴力做法,直接寄了
# 定义上、下、左、右
dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
# 是否在场地中
def is_in_mat(mat, row, col):
if 0 <= row < len(mat) and 0 <= col < len(mat[0]):
return True
# DFS
def dfs(mat, row, col, visited):
height = mat[row][col]
max_distance = 1
for d in dir:
new_row = row + d[0]
new_col = col + d[1]
if is_in_mat(mat, new_row, new_col) and not visited[new_row][new_col] and mat[new_row][new_col] < height:
visited[new_row][new_col] = True
distance = dfs(mat, new_row, new_col, visited)
max_distance = max(max_distance, distance)
return max_distance + 1
# 读取输入
n, m = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
# 遍历初始化
result = 0
list_maxdis = []
for i in range(n):
for j in range(m):
visited = [[False] * m for _ in range(n)]
visited[i][j] = True
distance = dfs(mat, i, j, visited)
u = max(result, distance)
list_maxdis.append(u)
# 输出结果
print(max(list_maxdis))
# 记忆优化做法,这个能过
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]
cache = [[-1] * m for _ in range(n)]
def dfs(x, y):
if cache[x][y] != -1:
return cache[x][y]
ans = 1
for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
xx = dx + x
yy = dy + y
if 0 <= xx < n and 0 <= yy < m and lst[xx][yy] < lst[x][y]:
ans = max(dfs(xx, yy) + 1, ans)
cache[x][y] = ans
return ans
res = 0
for i in range(n):
for j in range(m):
res = max(dfs(i, j), res)
print(res)
10、第十题
# 又是暴力做的,有两个数据过不去
n = int(input())
a = list(map(int, input().split()))
k = int(input())
result = []
for i in range(n):
left = max(0, i - k)
right = min(n - 1, i + k)
min_value = min(a[left:right+1])
result.append(min_value)
print(' '.join(map(str, result)))
# 自行dp吧,看到有大佬过了
n = int(input())
a = list(map(int, input().split()))
t = int(input())
dp = [0] * n
dp[0] = min(a[1 - t if 1 - t >= 0 else 0: 1 + t + 1])
for i in range(1, n):
p1 = i - t - 1 if i - t - 1 >= 0 else 0 # 左指针-1
p2 = i + t if i + t < n else n - 1
if a[p1] == dp[i - 1]: # 出区间了,重新计算
dp[i] = min(a[p1 + 1: p2])
else:
dp[i] = dp[i - 1] if a[p2] > dp[i - 1] else a[p2]
print(' '.join([str(x) for x in dp]))
11、第十一题
有64个六位数字,每个数各个位上的数字之和最大的是哪个?(填空题,有重复的找第一个)
nums = [454771, 329157, 801601, 580793, 755604, 931703, 529875, 361797, 604358, 529564, 574776, 821517, 195563, 688516, 223321, 607845, 284772, 603562, 543328, 707484, 533688, 380468, 233733, 257995, 896582, 670074, 912386, 702393, 722092, 834842, 126346, 606526, 376981, 910643, 413754, 945725, 817853, 651778, 350775, 676550, 316935, 487808, 939526, 900568, 423326, 298936, 927671, 539773, 136326, 717022, 886675, 466684, 436470, 558644, 267231, 902422, 743580, 857864, 529622, 320921, 595409, 486860, 951114, 558787]
nums = [454771, 329157, 801601, 580793, 755604, 931703, 529875, 361797,
604358, 529564, 574776, 821517, 195563, 688516, 223321, 607845,
284772, 603562, 543328, 707484, 533688, 380468, 233733, 257995,
896582, 670074, 912386, 702393, 722092, 834842, 126346, 606526,
376981, 910643, 413754, 945725, 817853, 651778, 350775, 676550,
316935, 487808, 939526, 900568, 423326, 298936, 927671, 539773,
136326, 717022, 886675, 466684, 436470, 558644, 267231, 902422,
743580, 857864, 529622, 320921, 595409, 486860, 951114, 558787]
uhhh = []
def uh(i):
a1 = str(i)[0]
a2 = str(i)[1]
a3 = str(i)[2]
a4 = str(i)[3]
a5 = str(i)[4]
a6 = str(i)[5]
s = int(a1)+int(a2)+int(a3)+int(a4)+int(a5)+int(a6)
return s
for u in nums:
uhhh.append(uh(u))
print(nums[uhhh.index(min(uhhh))])
答案是:223321。
12、第十二题
L = int(input())
count = 0
while L > 1:
L //= 2
count += 1
print(count+1)
13、第十三题
def delete_characters(string, n,m):
if string is None or n == 0 or m <= 0:
return string
if m >= n:
return ""
stack = []
for c in string:
while stack and c < stack[-1] and m > 0:
stack.pop()
m -= 1
stack.append(c)
while m > 0 and stack:
stack.pop()
m -= 1
result = ""
while stack:
result = stack.pop() + result
return result
n,m = map(int,input().split())
S = input()
result = delete_characters(S, n,m)
print(result)
文章出处登录后可见!
已经登录?立即刷新