# Tetrahedron

1 h 2 = 1 a 2 + 1 b 2 + 1 c 2 \cfrac{1}{h^2}=\cfrac{1}{a^2}+\cfrac{1}{b^2}+\cfrac{1}{c^2}

E ( x + y ) = E ( x ) + E ( y ) E(x+y)=E(x)+E(y)

// 百思不得其解 赛中3秒过了 赛后T cin改成scanf后4秒过了 hdu这是什么机制？？？
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int N = 6e6 + 10;
int n;

ll qpow(ll a, ll b) {
a %= mod;
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}

ll f[N], sum[N];

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

for (int i = 1, lim = 6e6; i <= lim; i++) {
f[i] = qpow(1ll * i * i, mod - 2);
sum[i] = (sum[i - 1] + f[i]) % mod;
}

int T;
cin >> T;
while (T--) {
cin >> n;
ll a = (qpow(n, mod - 2) * 3) % mod;
cout << ((a * sum[n]) % mod) << endl;
}
return 0;
}


Funny String

# Boring Game

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
vector<int> v[N];
int a[N];
int n, m, k;

int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

int T;
cin >> T;
for (int cs = 1; cs <= T; cs++) {

cin >> n >> k;
int lim = 2 * n * (1 << k);
m = (1 << k);
for (int i = 1; i <= m; i++) {
v[i].clear();
}
for (int i = 1; i <= lim; i++) {
cin >> a[i];
v[m].push_back(a[i]);
}
reverse(v[m].begin(), v[m].end());
for (int t = 0; t < k; t++) {
for (int i = m - (1 << t) + 1, j = i - 1; i <= m; i++, j--) {
int mid = v[i].size() / 2;
for (int l = 0; l < mid; l++) {
v[j].push_back(v[i].back());
v[i].pop_back();
}
}
}

for (int i = 2 * n - 1; i >= 0; i--) {
for (int j = 1; j <= m; j++) {
cout << v[j][i] << (j == m && i == 0 ? "\n" : " ");
}
}
}
return 0;
}


Expression
Array Repairing
Alice and Bob
Tree
Set2

# Paperfolding

E ( x ) = ∑ x × p ( x ) = ∑ x = 0 n C n x ( 2 x + 1 ) ( 2 n − x + 1 ) 2 n E(x)=\sum x\times p(x)=\sum^n_{x=0} \cfrac{C^x_n(2^x+1)(2^{n-x}+1)}{2^n}

∑ x = 0 n C n x ( 2 x + 1 ) ( 2 n − x + 1 ) = ∑ x = 0 n C n x ( 2 n + 2 x + 2 n − x + 1 ) = 2 n ∑ x = 0 n C n x + ( ∑ x = 0 n C n x 2 x + ∑ x = 0 n C n x 2 n − x ) + ∑ x = 0 n C n x \sum^n_{x=0}C^x_n(2^x+1)(2^{n-x}+1)\\=\sum^n_{x=0}C^x_n(2^n+2^x+2^{n-x}+1)\\=2^n\sum^n_{x=0}C^x_n+(\sum^n_{x=0} C^x_n2^x+\sum^n_{x=0} C^x_n2^{n-x})+\sum^n_{x=0} C^x_n

∑ x = 0 n C n x 2 x = ∑ x = 0 n C n x 2 x × 1 n − x = ( 2 + 1 ) n = 3 n \sum^n_{x=0} C^x_n2^x=\sum^n_{x=0} C^x_n2^x\times 1^{n-x}=(2+1)^n=3^n

( a + b ) n = ∑ k = 0 n C n k a k b n − k (a+b)^n=\sum^n_{k=0}C^k_na^kb^{n-k}
a = 1 a=1 b = 1 b=1 时，

( 1 + 1 ) n = ∑ k = 0 n C n k 1 k 1 n − k = ∑ k = 0 n C n k = 2 n (1+1)^n=\sum^n_{k=0}C^k_n1^k1^{n-k}=\sum^n_{k=0}C^k_n=2^n

∑ x = 0 n C n x 2 n − x = ∑ x = 0 n C n x 2 n − x × 1 x = ( 1 + 2 ) n = 3 n \sum^n_{x=0} C^x_n2^{n-x}=\sum^n_{x=0} C^x_n2^{n-x}\times 1^{x}=(1+2)^n=3^n

E ( x ) = 2 n + 1 + 2 × 3 n 2 n E(x)= 2^n+1+\cfrac{2\times3^n}{2^n}

a 1 = 6 a_1=6 a 2 = 10 a_2=10 a 3 = 18 a_3=18 a 4 = 34 a_4=34

a 2 − a 1 = 4 a_2-a_1=4 a 3 − a 2 = 8 a_3-a_2=8 a 4 − a 3 = 16 a_4-a_3=16

a n + 1 = a n + 2 n + 1 a_{n+1}=a_n+2^{n+1}

a n + 1 − x = a n + 2 n + 1 − x a_{n+1}-x=a_n+2^{n+1}-x

a n + 1 − 2 n + 2 = a n + 2 n + 1 − 2 n + 2 = a n + 2 n + 1 − 2 × 2 n + 1 = a n − 2 n + 1 a_{n+1}-2^{n+2}=a_n+2^{n+1}-2^{n+2}=a_n+2^{n+1}-2\times2^{n+1}=a_n-2^{n+1}

a n − 2 n + 1 = . . . = a 1 − 2 2 = 6 − 4 = 2 a_n-2^{n+1}=...=a_1-2^2=6-4=2

a n = 2 n + 1 + 2 a_n=2^{n+1}+2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;

namespace MOD { // 取模运算板子
const ll mod = 998244353;

ll qpow(ll a, ll b) {
a %= mod;
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}

ll Mul(ll a, ll b) {
return (a * b) % mod;
}

ll Sub(ll a, ll b) {
return (a - b + mod) % mod;
}

ll Add(ll a, ll b) {
return (a + b) % mod;
}
}
using namespace MOD;

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

int T;
cin >> T;
while (T--) {
cin >> n;
if (n == 0) cout << 4 << endl;
else if (n == 1) cout << 6 << endl;
else {
ll _2n = qpow(2, n);// 2^n
ll _3n = qpow(3, n); // 3^n
ll Inv_2n = qpow(_2n, mod - 2); // 1/2^n

cout << res << endl;
}
}
return 0;
}


Function
Exam

# Set1

c n t [ i ] cnt[i] 表示第 i i 个元素被留到最后的方案数

C i − 1 n − i × ( n − i ) ! C_{i-1}^{n-i}\times (n-i)!

C n 2 × C n − 2 2 × C n − 4 2 . . . × C 2 2 C^{2}_{n}\times C^{2}_{n-2} \times C^2_{n-4}...\times C^2_2 = n ( n − 1 ) 2 × ( n − 2 ) ( n − 3 ) 2 × . . . × 2 × 1 2 = n ! 2 n 2 =\cfrac{n(n-1)}{2}\times \cfrac{(n-2)(n-3)}{2} \times...\times \cfrac{2\times1}{2}=\cfrac{n!}{2^{\frac{n}{2}}}

( 2 i − n − 1 ) ! 2 2 i − n − 1 2 × 1 ( 2 i − n − 1 2 ) ! \cfrac{(2i-n-1)!}{2^\frac{2i-n-1}{2}}\times \frac{1}{(\frac{2i-n-1}{2})!}

c n t [ i ] = C i − 1 n − i × ( n − i ) ! × ( 2 i − n − 1 ) ! 2 2 i − n − 1 2 × 1 ( 2 i − n − 1 2 ) ! cnt[i]=C_{i-1}^{n-i}\times (n-i)! \times \cfrac{(2i-n-1)!}{2^\frac{2i-n-1}{2}}\times \frac{1}{(\frac{2i-n-1}{2})!}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int N = 5e6 + 10;
const int M = 5e6;
int n;

ll Mul(ll a, ll b) { return (a * b) % mod; }

ll Add(ll a, ll b) { return (a + b) % mod; }

ll Sub(ll a, ll b) { return (a - b + mod) % mod; }

ll qpow(ll a, ll b) {
a %= mod;
ll res = 1;
while (b) {
if (b & 1) res = Mul(res, a);
b >>= 1;
a = Mul(a, a);
}
return res;
}

ll fac[N], inv[N];
ll inv_2[N];// 1/(2^i)

void init(int n) {
fac[0] = inv[0] = inv_2[0] = 1;
int inv2 = qpow(2, mod - 2);
for (int i = 1; i <= n; ++i) {
fac[i] = Mul(fac[i - 1], i);
inv_2[i] = Mul(inv_2[i - 1], inv2);
inv[i] = Mul(inv[i - 1], qpow(i, mod - 2));
}
}

ll C(int n, int m) {
if (n < m || m < 0)return 0;
return Mul(Mul(fac[n], inv[m]), inv[n - m]);
}

ll cnt[N];

int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

init(M);
int T;
cin >> T;
for (int cs = 1; cs <= T; cs++) {

cin >> n;
ll sum = 0;
for (int i = 1; i <= n; i++) {
int tmp = i * 2 - n - 1;
if (tmp < 0) cnt[i] = 0;
else
cnt[i] = Mul(Mul(C(i - 1, n - i), fac[n - i]),
Mul(Mul(fac[tmp], inv_2[tmp / 2]), inv[tmp / 2]));
}

ll inv_sum = qpow(sum, mod - 2);
for (int i = 1; i <= n; i++) {
cout << Mul(cnt[i], inv_sum) << (i == n ? "\n" : " ");
}
}
return 0;
}


An Easy Matrix Problem

06-09 6万+
09-03 1544