蓝桥 第1场算法双周赛 python解析

蓝桥-第1场算法双周赛

时间:2023.10.14
地址:第1场算法双周赛
说明:持续更新中,,代码均为AC代码。

1. 三带一【算法赛】

题目分析

代码

t = int(input())
for i in range(t):
  s = input()
  for i in range(2):
    temp = s[i]
    if s.count(temp) == 3:
      print('Yes')
      break
    elif s.count(temp) == 1:
      if i == 1:
        print('No')
    else:
      print('No')
      break

2. 数树数【算法赛】

题目分析

代码

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

for i in range(q):
  s = input()
  lavel = [1, 2]
  for t in s:
    if t == 'L':
      node = 0
    else:
      node = 1
    current = lavel[node]
    lavel[0], lavel[1] = current*2-1, current*2
  print(current)

3. 分组【算法赛】

题目分析

、、、、

代码

def check(nums, mid):
  res = 1
  minn = maxn = nums[0]
  
  for i in range(1, n):
    minn = min(minn, nums[i])
    maxn = max(maxn, nums[i])

    if maxn - minn > mid:
      res += 1
      if res > k:
        return False
      minn = maxn = nums[i]
  return True

n, k = map(int, input().split())
nums = [int(i) for i in input().split()]

nums.sort()
lmin, lmax = 0, nums[-1] - nums[0]
while lmin < lmax:
  mid = (lmin + lmax) // 2
  if check(nums, mid):
    lmax = mid
  else:
    lmin = mid + 1

print(lmin)

4. 健身【算法赛】

题目分析

、、、、

代码

n, m, q = map(int, input().split())
approched = [int(i) for i in input().split()]
li = []
for _ in range(m):
  k, s = map(int, input().split())
  li.append([2**k, s])

li.sort(key=lambda x:x[-1], reverse=True)

days = ['0']*n
for j in approched:
  days[j-1] = '1'

days_n = [len(temp) for temp in ''.join(days).split('1')]

def max_s(day):
  dp = [0] * (day+1)
  for i in range(1, day+1):
    for j in range(m):
      if li[j][0] <= i:
        dp[i] = max(dp[i], dp[i-li[j][0]]+li[j][1])
  return dp[day]
res = 0
for day in days_n:
  res += max_s(day)
print(res)

5.

题目分析

代码

6.

题目分析

代码

小结

还有待提高啊,我,两个小时只做出了四题。

你可能感兴趣的:(#,算法学习的小记录,python,算法)