def egcd(a, b): """扩展欧几里得""" if 0 == b: return1, 0, a x, y, q = egcd(b, a % b) x, y = y, (x - a // b * y) return x, y, q n = int(input()) flag = False a1, r1 = map(int, input().split()) for _ in range(n-1): a2, r2 = map(int, input().split()) R = r2-r1 x, y, d = egcd(a1, a2) tmp = a2//d if R%d != 0: flag = True r1=((x*R//d)%tmp+tmp)%tmp*a1+r1 a1=a1*(a2//d) lcm = a1 ans = (r1%lcm+lcm)%lcm
if flag: print("Tankernb!") exit(0)
fac = [1, 2] cur = 2 while True: tmp = fac[cur-1] + fac[cur-2] if tmp > ans: break fac.append(tmp) cur += 1
flag = False for v in fac: if v == ans: flag = True break
#include<bits/stdc++.h> #define rep(i, a, b) for(int i = (a); i <= (b); ++i) #define per(i, a, b) for(int i = (a); i >= (b); --i) #define debug(x) cerr << #x << ' ' << x << endl; usingnamespace std;
bit.n = n; int cur = 1; rep(i, 1, n){ rep(j, 0, (int)v[i].size()-1){ bit.add(v[i][j], 1); } while(cur <= m && s[cur].r == i){ s[cur].val = bit.get(i) - bit.get(s[cur].l-1); cur++; } } sort(s + 1, s + 1 + m, [](const node &a, const node &b){return a.id < b.id;});
rep(i, 1, m) printf("%d\n", s[i].val); return0; }
J. Random Access Iterator
感觉这个题目属于很简单的树上递推的题目。
题目的意思就是从树的根结点出发,每次在节点的儿子中随机选择一个,递归,重复子节点个数次。
我们先一次 $DFS$ 更新出来子树的高度和节点的子节点树,$h[x]$ 和 $son[x]$。
首先当一个子节点子树的高度加一小于当前节点的高度的时候这个子节点是没用的,因为它更新不到最大值。
而如果可以的话就加上这个子树的递归求出最大值的概率。叶子节点概率为一。
形式化来说就是:
1 2 3 4 5 6 7 8 9 10 11
function DFS(x) k <- the number of sons of x if k is 0do return1 p <- 0 for son of x do if h[x] equal to h[son] + 1do p += DFS(son) p <- p divided by k res <- 1 - pow(1-p, k) return res
#include<bits/stdc++.h> #define rep(i, a, b) for(ll i = (a); i <= (b); ++i) #define per(i, a, b) for(ll i = (a); i >= (b); --i) #define debug(x) cerr << #x << ' ' << x << endl; usingnamespace std;
typedeflonglong ll; const ll MAXN = 1e6 + 7; const ll mod = 1e9 + 7; ll qpow(ll a, ll b){ ll res = 1; while(b){ if(b&1) res = 1ll * res * a % mod; a = 1ll * a * a % mod; b >>= 1; } res = res%mod + mod; return res%mod; }