快读:
1 inline char gc() { 2 static char buf[100000], *p1 = buf, *p2 = buf; 3 return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; 4 } 5 6 //#define gc getchar 7 inline int read() { 8 int x = 0; char ch = gc(); bool f = 1; 9 for (; !isdigit(ch); ch = gc()) if (ch == '-') f = -1;10 for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0';11 return f * x;12 }
康托展开:
1 LL fac[20]; 2 3 void init() { 4 fac[0] = 1; 5 for (int i = 1; i <= 15; ++i) fac[i] = fac[i - 1] * i; 6 } 7 8 LL cantor(int a[]) { 9 LL res = 0;10 for (int i = 1; i <= 8; ++i) {11 int cnt = 0;12 for (int j = i + 1; j <= 8; ++j)13 cnt += a[j] < a[i];14 res += cnt * fac[8 - i];15 }16 return res;17 }18 19 void inv_cantor(int n, LL k) {20 vector vec; k--;21 int a[20];22 for (int i = 1; i <= n; ++i) vec.push_back(i);23 for (int i = n; i >= 1; --i) {24 LL p = k / fac[i - 1]; k %= fac[i - 1];25 sort(vec.begin(), vec.end());26 a[n - i + 1] = vec[p];27 vec.erase(vec.begin() + t);28 }29 for (int i = 1; i <= n; ++i) printf("%d ", a[i]);30 }
幂次求和:
Σ (i, 1, n) (i) = n * (n + 1) / 2 = 1 / 2 * n 2 + 1 / 2 * n
Σ (i, 1, n) (i 2) = n * (n + 1) * (2n + 1) / 6 = 1 / 3 * n 3 + 1 / 2 * n 2 + 1 / 6 * n
Σ (i, 1, n) (i 3) = (n * (n + 1) / 2) 2 = 1 / 4 * n 4 + 1 / 2 * n 3 + 1 / 4 * n 2
Σ (i, 1, n) (i 4) = n * (n + 1) * (2n + 1) * (3x 2 + 3x - 1) / 30 = 1 / 5 * n 5 + 1 / 2 * n 4 + 1 / 3 * n 3 - 1 / 30 * n
Σ (i, 1, n) (i 4) = n 2 * (n + 1) * (2n 3 + 4n 2 + n - 1) / 12
海伦公式:
S = sqrt(p * (p - a) * (p - b) * (p - c));
p = (a + b + c) / 2.0;