structCartesian_Tree { structnode { int id, val, fa; int son[2]; node() {} node (int id, int val, int fa) : id(id), val(val), fa(fa) { son[0] = son[1] = 0; } }t[N]; int root, l[N], r[N]; voidinit(){ t[0] = node(0, 0, 0); } voidbuild(int n, int *a){ for (int i = 1; i <= n; ++i) { t[i] = node(i, a[i], 0); } for (int i = 1; i <= n; ++i) { int k = i - 1; while (t[k].val > t[i].val) { k = t[k].fa; } t[i].son[0] = t[k].son[1]; t[k].son[1] = i; t[i].fa = k; t[t[i].son[0]].fa = i; } root = t[0].son[1]; } intDFS(int u){ if (!u) return0; l[t[u].id] = DFS(t[u].son[0]); r[t[u].id] = DFS(t[u].son[1]); return l[t[u].id] + r[t[u].id] + 1; } }t[2];
boolcheck(int x){ t[0].init(); t[1].init(); t[0].build(x, a); t[1].build(x, b); t[0].DFS(t[0].root); t[1].DFS(t[1].root); for (int i = 1; i <= x; ++i) { if (t[0].l[i] != t[1].l[i] || t[0].r[i] != t[1].r[i]) return0; } return1; }
intmain(){ while (scanf("%d", &n) != EOF) { for (int i = 1; i <= n; ++i) { scanf("%d", a + i); } for (int i = 1; i <= n; ++i) { scanf("%d", b + i); } int l = 1, r = n, res = -1; while (r - l >= 0) { int mid = (l + r) >> 1; if (check(mid)) { res = mid; l = mid + 1; } else { r = mid - 1; } } printf("%d\n", res); } return0; }
Frac operator+(const Frac &other) const { ll up = x * other.y + y * other.x; ll down = y * other.y; ll G = __gcd(up, down); return {up / G, down / G}; }
Frac operator-(const Frac &other) const { ll up = x * other.y - y * other.x; ll down = y * other.y; ll G = __gcd(up, down); return {up / G, down / G}; }
Frac operator*(const Frac &other) const { ll up = x * other.x; ll down = y * other.y; ll G = __gcd(up, down); return {up / G, down / G}; }
intmain(){ while (~scanf("%d %lld", &n, &m)) { for (int i = 1; i <= n; ++i) { scanf("%lld", arr + i); } sort(arr + 1, arr + 1 + n, greater<ll>()); ll need = m; Frac ans = Frac(0, 1); for (int i = 1; i <= n; ++i) { if (i < n && (arr[i] - arr[i + 1]) * i <= need) { need -= (arr[i] - arr[i + 1]) * i; } else { ans = ans + Frac((i * arr[i] - need) * (i * arr[i] - need), 1ll * i * m * m); for (int j = i + 1; j <= n; ++j) { ans = ans + Frac(arr[j] * arr[j], m * m); } ans.out(); break; } } } return0; }
intmain(){ while (~scanf("%d %d", &n, &m)) { for (int i = 0; i <= n + m; ++i) { for (int j = 0; j <= n + m; ++j) { dp[i][j] = 0ll; } } dp[0][0] = 1ll; for (int i = 0; i <= n + m; ++i) { for (int j = 0; j <= n + m; ++j) { if (i + 1 - n <= j && j - m <= i + 1) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % p; } if (j + 1 - m <= i && i - n <= j + 1) { dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % p; } } } printf("%lld\n", dp[n + m][n + m]); } return0; }
intmain(){ while (~scanf("%lld %lld", &p[1].x, &p[1].y)) { p[2].input(); p[3].input(); ll ans = abs((p[1] - p[2]) ^ (p[1] - p[3])); ans *= 11; printf("%lld\n", ans); } return0; }
J. Fraction Comparision
题意:比较ax和by的大小
思路:签到
1 2 3 4 5 6 7 8 9 10 11 12 13
whileTrue : try : x, a, y, b = map(int, input().split()) A = x * b B = y * a if A == B : print('=') elif A < B : print('<') elif A > B : print('>') except EOFError : break