

链接: 4615. 相遇问题

签到题,速度加起来计算时间。
最后乘回去判断整除。
import collections
import io
import os
import sys
from collections import deque
if sys.hexversion == 50923504:
sys.stdin = open('input.txt')
RI = lambda: map(int, input().split())
else:
input = sys.stdin.readline
input_int = sys.stdin.buffer.readline
RI = lambda: map(int, input_int().split())
RS = lambda: input().strip().split()
RILST = lambda: list(RI())
MOD = 10 ** 9 + 7
def solve(x,y,a,b):
# print(x,y,a,b)
ans = (y-x)//(a+b)
if ans * (a+b) == y-x:
print( ans)
return
print(-1)
if __name__ == '__main__':
t, = RI()
for _ in range(t):
x,y,a,b = RI()
solve(x,y,a,b)
链接: 4616. 击中战舰

import collections
import io
import os
import sys
from collections import deque
from functools import lru_cache
if sys.hexversion == 50923504:
sys.stdin = open('input.txt')
RI = lambda: map(int, input().split())
else:
input = sys.stdin.readline
input_int = sys.stdin.buffer.readline
RI = lambda: map(int, input_int().split())
RS = lambda: input().strip().split()
RILST = lambda: list(RI())
MOD = 10 ** 9 + 7
def solve(n, a, b, s):
ks = [-1]
for i, v in enumerate(s):
if v == '1':
ks.append(i)
ks.append(n)
kong = []
c = 0
for i in range(1, k + 2):
d = ks[i] - ks[i - 1] - 1
c += d // b
kong.append((d, ks[i - 1], ks[i]))
hit = c - a + 1
print(hit)
ans = []
for d,i,j in kong:
while i+b< j:
i += b
ans.append(i)
if len(ans) == hit:
print(' '.join(map(lambda x: str(x + 1), ans)))
return
if __name__ == '__main__':
n, a, b, k = RI()
s, = RS()
solve(n, a, b, s)
链接: 4617. 解方程

这题找纸笔找半天,难受啊。
位运算知识。

import collections
import io
import os
import sys
from bisect import bisect_right
from collections import *
from itertools import accumulate
from math import inf
if sys.hexversion == 50923504:
sys.stdin = open('input.txt')
RI = lambda: map(int, input().split())
else:
input = sys.stdin.readline
input_int = sys.stdin.buffer.readline
RI = lambda: map(int, input_int().split())
RS = lambda: input().strip().split()
RILST = lambda: list(RI())
MOD = 10 ** 9 + 7
def solve(a):
# a = 1
# print(a)
c = bin(a).count('1')
# a.bit_count() py3.10以上才有
print(2**c)
if __name__ == '__main__':
t, = RI()
for _ in range(t):
a, = RI()
solve(a)