漏写的数字
#pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<stack> #include<string> #include<functional> //#include<bits/stdc++.h> using namespace std; typedef long long lint; int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } char str[500]; int s[500]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif std::ios::sync_with_stdio(0), cin.tie(0); cin >> str; bool f, f1; int n = strlen(str); for (int i = 0; i < n; i++) s[i] = str[i] - '0'; int ans; f = true, f1 = false; int b = s[0]; int ptr = 1; while (ptr < n) { b++; if (b < 10) { if (s[ptr] == b) { ptr++; continue; } else { if (f1) { f = false; break; } else { f1 = true; ans = b; } } } else { if (s[ptr] == b / 10 && s[ptr + 1] == b % 10) { ptr += 2; continue; } else { if (f1) { f = false; break; } else { f1 = true; ans = b; } } } } if (f && f1) { cout << ans << endl; return 0; } f = true, f1 = false; b = s[0] * 10 + s[1]; ptr = 2; while (ptr < n) { b++; if (b < 10) { if (s[ptr] == b) { ptr++; continue; } else { if (f1) { f = false; break; } else { f1 = true; ans = b; ptr++; } } } else { if (s[ptr] == b / 10 && s[ptr + 1] == b % 10) { ptr += 2; continue; } else { if (f1) { f = false; break; } else { f1 = true; ans = b; } } } } if (f && f1) { cout << ans << endl; return 0; } return 0; }
扁平化管理
#pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<stack> #include<string> #include<functional> //#include<bits/stdc++.h> using namespace std; typedef long long lint; int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } lint a[100][100]; const lint inf = 0x7FFFFFFFFFFFFFFF; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif std::ios::sync_with_stdio(0), cin.tie(0); for (int i = 0; i < 100; i++) { for (int j = 1; j < 100; j++) { lint aaa = 1, tmp = 1; if (i < j - 1) continue; for (int k = 1; k < j; k++) { aaa *= (i - k + 1); tmp += aaa; if (tmp > 1e18) break; } if (tmp > 1e18) a[i][j] = inf; else a[i][j] = tmp; } } lint n, l; cin >> n >> l; bool f = false; for (int i = 0; i < 100; i++) { for (int j = 0; j < min((lint)100, l + 1); j++) { if (a[i][j] >= n && !f) { cout << i << endl; f = true; } } } if (!f) { if (l == 2) cout << n - 1 << endl; else if (l == 3) { lint tmp = (lint)sqrt(n); if (tmp * tmp + 1 >= n) cout << tmp << endl; else cout << tmp + 1 << endl; } else { for (int i = 0;; i++) { if (i < l - 1) continue; lint aaa = 1, tmp = 1; for (int k = 1; k < l; k++) { aaa *= (i - k + 1); tmp += aaa; if (tmp > 1e18) break; } if (tmp > n) { cout << i << endl; break; } } } } return 0; }
小球染色
动态规划:dp[i][j]表示决定了前i个的颜色,最后j个颜色相同的方法数。
#pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> #include<stack> #include<string> #include<functional> //#include<bits/stdc++.h> using namespace std; typedef long long lint; int cmp(const void * x, const void * y) { #define datatype int datatype dx = *((datatype *)(x)), dy = *((datatype *)(y)); //x < y return dx > dy ? 1 : -1; #undef datatype } lint dp[1005][1005]; const int mod = 1000000007; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif std::ios::sync_with_stdio(0), cin.tie(0); int n, m, k; cin >> n >> m >> k; memset(dp, 0, sizeof(dp)); dp[1][1] = m; for (int i = 1; i <= n; i++) { for (int j = 1; j < k; j++) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod; dp[i + 1][1] = (dp[i + 1][1] + dp[i][j] * (m - 1)) % mod; } } lint ans = 0; for (int i = 1; i < k; i++) ans = (ans + dp[n][i]) % mod; cout << ans << endl; return 0; }
三角形面积和2