Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2587bf8

Browse files
committed
「蓝桥」1228 第 5 场 算法季度赛
1 parent 5d31868 commit 2587bf8

File tree

7 files changed

+205
-0
lines changed

7 files changed

+205
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
加油,2025【算法赛】
3+
"""
4+
if __name__ == '__main__':
5+
print(2025)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
开赛主题曲【算法赛】
3+
"""
4+
from string import ascii_lowercase
5+
6+
if __name__ == '__main__':
7+
n = int(input())
8+
s = input()
9+
to_compare = 'lanqiobe'
10+
11+
ans = -2
12+
chosen = ''
13+
14+
d = dict(zip(ascii_lowercase, list(range(1, 27))))
15+
16+
for i in range(n):
17+
st = set()
18+
cur = 0
19+
20+
for j in range(i, n):
21+
if s[j] in st:
22+
break
23+
st.add(s[j])
24+
cur += d[s[j]]
25+
26+
res = -1
27+
for start in range(i, j + 1):
28+
for step in range(8):
29+
if start + step > j or start + step >= n or s[start + step] != to_compare[step]:
30+
break
31+
res = max(res, step)
32+
res = (res + 1) * 10 + cur
33+
if res == ans:
34+
chosen = min(chosen, s[i:j + 1])
35+
elif res > ans:
36+
ans = res
37+
chosen = s[i:j + 1]
38+
39+
print(chosen)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
BlueAI【算法赛】
3+
"""
4+
if __name__ == '__main__':
5+
n = int(input())
6+
grid = [list(input()) for _ in range(n)]
7+
8+
dirs = [(i, j) for i in [-1, 1] for j in [-1, 1]]
9+
10+
11+
def dfs(i, j):
12+
res = 0
13+
for di, dj in dirs:
14+
if 0 <= i + 2 * di < n and 0 <= j + 2 * dj < n \
15+
and grid[i + di][j + dj] == 'Q' and grid[i + 2 * di][j + 2 * dj] == '.':
16+
grid[i][j] = '.'
17+
grid[i + di][j + dj] = '.'
18+
grid[i + 2 * di][j + 2 * dj] = 'L'
19+
res = max(res, dfs(i + 2 * di, j + 2 * dj) + 1)
20+
grid[i][j] = 'L'
21+
grid[i + di][j + dj] = 'Q'
22+
grid[i + 2 * di][j + 2 * dj] = '.'
23+
return res
24+
25+
26+
ans = 0
27+
for i in range(n):
28+
for j in range(n):
29+
if grid[i][j] == 'L':
30+
ans = max(ans, dfs(i, j))
31+
32+
print(ans)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
秃头风险【算法赛】
3+
"""
4+
import math
5+
6+
if __name__ == '__main__':
7+
n = int(input())
8+
nums = list(map(int, input().split()))
9+
10+
ans = 0
11+
for v in nums:
12+
if v % 2 == 0:
13+
ans += 1
14+
elif math.isqrt(v) ** 2 == v:
15+
ans += 1
16+
17+
print(ans)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
精准难度【算法赛】
3+
4+
从某个位置乘到第 i 个位置 mod 2025 = x 的子数组有多少个
5+
"""
6+
if __name__ == '__main__':
7+
n = int(input())
8+
nums = list(map(int, input().split()))
9+
10+
dp = [0] * 2025
11+
ndp = [0] * 2025
12+
ans = 0
13+
14+
for v in nums:
15+
v %= 2025
16+
17+
for i in range(2025):
18+
ndp[i * v % 2025] ^= dp[i]
19+
ndp[v] ^= 1
20+
21+
for i in range(2025):
22+
dp[i] = ndp[i]
23+
ndp[i] = 0
24+
if dp[i]:
25+
ans ^= i
26+
27+
print(ans)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
排序题目【算法赛】
3+
"""
4+
5+
6+
def prep(p):
7+
pi = [0] * len(p)
8+
j = 0
9+
for i in range(1, len(p)):
10+
while j != 0 and p[j] != p[i]:
11+
j = pi[j - 1]
12+
if p[j] == p[i]:
13+
j += 1
14+
pi[i] = j
15+
return pi
16+
17+
18+
def solve():
19+
n = int(input())
20+
nums = list(map(int, input().split()))
21+
22+
flg = True
23+
for i in range(1, n):
24+
if nums[i] < nums[i - 1]:
25+
flg = False
26+
if flg:
27+
print('0')
28+
return
29+
30+
st = sorted(nums)
31+
32+
diff_idx = 0
33+
for i in range(n):
34+
if nums[i] != st[i]:
35+
diff_idx = i
36+
37+
tmp = st[:diff_idx + 1] + [-1] + nums[:diff_idx + 1] * 2
38+
39+
if diff_idx + 1 in prep(tmp):
40+
print(diff_idx + 1)
41+
else:
42+
print(diff_idx + 3)
43+
44+
45+
if __name__ == '__main__':
46+
solve()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
铺设地砖【算法赛】
3+
"""
4+
5+
6+
def matrix_mul(A, B, mod=10 ** 9 + 7):
7+
n, m = len(A), len(A[0])
8+
p = len(B[0])
9+
ans = [[0] * p for _ in range(n)]
10+
for i in range(n):
11+
for j in range(m):
12+
for k in range(p):
13+
ans[i][k] += A[i][j] * B[j][k]
14+
ans[i][k] %= mod
15+
return ans
16+
17+
18+
def matrix_pow(x, n, mod):
19+
if n == 1: return x
20+
if n == 2: return matrix_mul(x, x, mod)
21+
v = matrix_pow(x, n // 2, mod)
22+
ans = matrix_mul(v, v, mod)
23+
if n % 2 == 0:
24+
return ans
25+
return matrix_mul(ans, x, mod)
26+
27+
28+
if __name__ == '__main__':
29+
t = int(input())
30+
outs = []
31+
mod = 10 ** 9 + 7
32+
33+
grid = [[1, 1, 0], [1, 0, 1], [0, 1, 1]]
34+
35+
for _ in range(t):
36+
n = int(input())
37+
outs.append(sum(matrix_pow(grid, n, mod)[0][1:]) % mod)
38+
39+
print(*outs, sep='\n')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /