日期
规定一年a[0]个月,每月a[1]天,每周a[3]天,周一至周a[3]为[a-z]. 假设第1年第1个月第1天为a,求b[2]年b[1]月b[0]天为duo
import sys a = sys.stdin.readline().strip() b = sys.stdin.readline().strip() a = [30, 12, 7] b = [7, 2, 2] days = a[0] months = a[1] weeks = a[2] total_days = (days*months)*(b[2]-1) + days*(b[1]-1) + (b[0]-1) offset = total_days % weeks print(chr(ord("a")+offset))
并查集
import sys N = int(1e5) un_id = [i for i in range(N)] def connect(a, b): a_id = un_id[a] b_id = un_id[b] if a_id == b_id: return True for i in range(N): if un_id[i] == a_id: un_id[i] = b_id n = int(sys.stdin.readline().strip()) for i in range(n): # 读取每一行 line = sys.stdin.readline().strip() # 把每一行的数字分隔后转化成int列表 values = list(map(int, line.split())) if values[0] == 1: connect(values[1], values[2]) elif values[0] == 2: a = values[1] % values[3] b = values[2] % values[3] if un_id[a] == un_id[b]: print("YES") else: print("NO")
全部评论
(0) 回帖