Codeforces round #256 (Div. 2)
Question Link
Question A: There is nothing to say about water. You can determine the quantity required for each of the two methods. In addition, you can check whether the quantity exceeds the limit.
Question B: First count the letters, check whether there are any extra characters in string B, judge the need tree, and then determine whether B can match a. If yes and the length is different, it is auto, if the length is the same, array is used; otherwise, both is used.
Question C: greedy. Each time you choose the lowest horizontal brush, several more sub-states will be displayed after the brush is finished. You can solve the problem using recursion.
Question D: Binary reasoning, binary answer, so for this answer, in the next n rows, there are m/2 corresponding to 2nd rows, and 3rd rows have M/3... and so on, we can find that the answer operator does not conform to the K number, and use the second point to constantly approach the answer.
Question E: brute-force attacks cannot be believed. Processing factor X out of DFS brute-force recursion outputs the answer, making great miracles.
Code:
A:
#include <stdio.h>#include <string.h>int a[3], b[3], n;int main() {int i;for (i = 0; i < 3; i++)scanf("%d", &a[i]);for (i = 0; i < 3; i++)scanf("%d", &b[i]);scanf("%d", &n);int aa = a[0] + a[1] + a[2];int bb = b[0] + b[1] + b[2];if (n >= (aa / 5 + (aa % 5 != 0) + bb / 10 + (bb % 10 != 0)))printf("YES\n");else printf("NO\n");return 0;}
B:
#include <stdio.h>#include <string.h>char a[105], b[105];int vis[30];void solve(char *str, int val) {for (int i = 0; i < strlen(str); i++)vis[str[i] - 'a'] += val;}bool jud(char *a, char *b) {int i = 0, j = 0;while (i < strlen(a) && j < strlen(b)) {if (b[j] == a[i]) {i++; j++;}else i++;}if (j == strlen(b)) return true;return false;}void gao() {int i;for (i = 0; i < 26; i++) {if (vis[i] > 0) {printf("need tree\n");return;}}if (jud(a, b)) {printf("automaton\n");}else {if (strlen(a) == strlen(b)) printf("array\n");else printf("both\n");}}int main() {scanf("%s%s", a, b);solve(b, 1);solve(a, -1);gao();return 0;}
C:
#include <stdio.h>#include <string.h>#define min(a,b) ((a)<(b)?(a):(b))#define INF 0x3f3f3f3fint n, a[5005];int dfs(int l, int r, int now) { if (l == r) return 0; int i, Min = INF; for (i = l; i < r; i++) Min = min(Min, a[i]); int ans = Min - now, L = l; for (i = l; i < r; i++) { if (a[i] == Min) { ans += dfs(L, i, Min); L = i + 1; } } ans += dfs(L, r, Min); return min(r - l, ans);}int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); printf("%d\n", dfs(0, n, 0)); return 0;}
D:
#include <stdio.h>#include <string.h>#define min(a,b) ((a)<(b)?(a):(b))__int64 n, m, k;bool judge(__int64 mid) {__int64 sum = 0;for (__int64 i = 1; i <= n; i++) {sum += min(m, (mid / i));}return sum >= k;}__int64 solve() {__int64 l = 1, r = n * m;while (l < r) {__int64 mid = (l + r) / 2;if (judge(mid)) r = mid;else l = mid + 1;}return l;}int main() {scanf("%I64d%I64d%I64d", &n, &m, &k);if (n > m) {__int64 t = n;n = m;m = t;}printf("%I64d\n", solve());return 0;}
E:
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;typedef __int64 ll;const int N = 100005;ll x, k, frac[N], fn = 0;void tra(ll x) { ll m = (ll)sqrt(x); for (ll i = 1; i <= m; i++) { if (x % i) continue; frac[fn++] = i; if (x / i != i) frac[fn++] = x / i; } sort(frac, frac + fn);}ll s = 0;void dfs(ll x, ll k) { if (s >= 100000) return; if (k == 0 || x == 1) { printf("%I64d ", x); s++; return; } for (ll i = 0; i < fn && frac[i] <= x; i++) { if (x % frac[i]) continue; dfs(frac[i], k - 1); if (s >= 100000) return; }}int main() { scanf("%I64d%I64d", &x, &k); tra(x); dfs(x, k); return 0;}