Codeforces Round #289 (Div. 2, acm icpc Rules) (A, B, C, E ),
A: Water question. You can pre-process the question and output it.
B: First find out the largest and smallest parts, so that the smallest part is 1, and then the largest part is 1, 3, 4, 5... so if MAX-MIN> k is NO, otherwise the answer will be constructed based on this
C: greedy strategy. To keep the number as small as possible, compare it with the previous number. If the sum is smaller than the previous one, find a new number first, make the sum smaller than the required number, and the number is greater than the minimum value of the previous number. The method is to keep putting 0 places at the end. Now, the only difference is the need for a bigger sum. This is greedy, from the end to 9 as much as possible.
E: A counting problem. In fact, you only need to consider the value added to each letter. For each letter, the length that can reach the leftmost and rightmost is + 1, but the largest one in the middle is: 1/I + 1/(I + 1) + 1/(I + 2 )...., I is the value of the distance between the number and the two sides. For example, if the total length is 7 and the current position is 2, then I is from 3 to 6, because there are more than 6 following, you only need to add the sum of 1/(n-I + 1) * I calculated from the following forward, so we need to pre-process the two Arrays for counting, specific Code:
A:
#include <cstdio>#include <cstring>using namespace std;int n, a[15][15];int main() { for (int i = 1; i <= 10; i++) a[1][i] = a[i][1] = 1; for (int i = 2; i <= 10; i++) for (int j = 2; j <= 10; j++) a[i][j] = a[i - 1][j] + a[i][j - 1]; while (~scanf("%d", &n)){ printf("%d\n", a[n][n]); } return 0;}
B:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n, k, a[105];int main() { while (~scanf("%d%d", &n, &k)) { int Min = 105, Max = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); Min = min(Min, a[i]); Max = max(Max, a[i]); } int use = min(k, Min); int one = Min / use; int yu = Min % use; if (Max - Min > k) printf("NO\n"); else { printf("YES\n"); for (int i = 0; i < n; i++) { printf("1"); for (int j = 2; j <= Min; j++) printf(" 1"); for (int j = Min + 1; j <= a[i]; j++) printf(" %d", j - Min); printf("\n"); } } } return 0;}
C:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 305;int n, b[N];int num[10005], nn;void find(int cha) { for (int i = 0; i < nn; i++) { if (cha > 0) { num[i] += 1; for (int j = i; j < nn; j++) { num[j + 1] += num[j] / 10; num[j] %= 10; } if (num[nn]) nn++; return; } cha += num[i]; num[i] = 0; } num[nn++] = 1;}int main() { while (~scanf("%d", &n)) { nn = 1; memset(num, 0, sizeof(num)); for (int i = 0; i < n; i++) scanf("%d", &b[i]); for (int i = 0; i < n; i++) { int tmp = 0; for (int i = 0; i < nn; i++) tmp += num[i]; int cha = b[i] - tmp; if (cha <= 0) find(cha); tmp = 0; for (int i = 0; i < nn; i++) tmp += num[i]; cha = b[i] - tmp; for (int i = 0; i < nn; i++) { if (num[i] + cha <= 9) { num[i] += cha; cha = 0; break; } else { cha = max(cha - 9 + num[i], 0); num[i] = 9; } } if (cha) { while (cha) { num[nn++] = min(cha, 9); cha = max(cha - 9, 0); } } for (int i = nn - 1; i >= 0; i--) printf("%d", num[i]); printf("\n"); } } return 0;}
E:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 500005;char str[N];double cal1[N], cal2[N];int vis[1005];double ans;int main() { gets(str + 1); int n = strlen(str + 1); for (int i = 1; i <= n; i++) { cal1[i] = cal1[i - 1] + 1.0 / i; cal2[i] = cal2[i - 1] + 1.0 / (n - i + 1) * i; } ans = 0; memset(vis, 0, sizeof(vis)); vis['I'] = vis['E'] = vis['A'] = vis['O'] = vis['U'] = vis['Y'] = 1; for (int i = 1; i <= n; i++) { if (vis[str[i]]) { int c = min(i, n - i + 1); ans += c * (cal1[n - c + 1] - cal1[c]) + c + cal2[c - 1]; } } printf("%.10lf\n", ans); return 0;}