Codeforce-- 思维题
2-11 Eat the chip
思路:题意可知,a从下往上走,b从上往下走,我们可以思考一个问题,在某一个回合,如果a和b在同一列中(a是Alice,b是Bob),一方怎么走,另外一方就跟着这一方走,所以同一列的时候是该回合后手的必胜态,先手的必败态。于是可以递推:如果在走到边界的时候有机会仍然保持b在a的上方,那么有机会分出胜负,因为一方不可以走出边界,所以ya-yb一定会发生变化,直到xa-xb = 0
import sys
#file I/O
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
#faster I/O
input = sys.stdin.readline
sys.setrecursionlimit(30)
def print(ans='',end = '\n'):
sys.stdout.write(str(ans) + end)
def solve() -> None:
n,m,xa,ya,xb,yb = map(int,input().split())
flag = bool((xb - xa) % 2)
if not flag:
winner = "Bob"
if xa >= xb:
win = False
elif ya == yb:
win = True
else:
if yb > ya:
n_turn = yb - 1
else:
n_turn = m - yb
win = xb - 2 * n_turn >= xa
else:
winner = "Alice"
xa += 1
ya += 0 if yb - ya == 0 else 1 if yb - ya > 0 else -1
if xa > xb:
win = False
elif ya == yb:
win = True
else:
if ya < yb :
n_turn = m - ya
else:
n_turn = ya - 1
win = xb - 2 * n_turn >= xa
print(winner if win else "Draw")
T = int(input())
for _ in range(T):
solve()
CF1920C-Partitioning the Array
import sys
import math
#file I/O
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
#faster I/O
input = sys.stdin.readline
sys.setrecursionlimit(30)
def write(ans='',ends = '\n'):
sys.stdout.write(str(ans) + ends)
def solve() -> None:
n = int(input())
a = [int(x) for x in input().split()]
a.insert(0,0)
ans = 0
for k in range(1,n+1):
if n % k == 0:
res = 0
for i in range(1,n-k+1):
res = math.gcd(res,abs(a[i]-a[i+k]))
ans += res != 1
write(ans)
T = int(input())
for _ in range(T):
solve()
CF1917C-Watering an Array
import sys
import math
from collections import Counter
#file I/O
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
#faster I/O
input = sys.stdin.readline
sys.setrecursionlimit(30)
def write(ans='',ends = '\n'):
sys.stdout.write(str(ans) + ends)
def solve() -> None:
n,k,d = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(min(d,2*n+1)):
cur = (d-i-1) // 2
for j in range(n):
cur += a[j] == j+1
ans = max(ans,cur)
for j in range(b[i%k]):
a[j] += 1
write(ans)
T = int(input())
for _ in range(T):
solve()