There are $n$ people, each needing $x_i$ units of food. The plate size and cost both equal the amount of food, and everyone wants plates of the same size. Find the minimum total cost and the largest usable plate size.
The wording is convoluted, but it is another easy problem: sum for the minimum cost, and take the GCD of all values for the largest plate.
There are $n$ bamboos of heights $h_i$. Decrease one bamboo by $1$ and increase every other bamboo by $1$ in each move. Can all heights eventually become equal?
An interesting problem that I overthought that night. First, several bamboos of the same height can be treated as one. Decrease the tallest by 1 and increase the rest by 1; for the tallest and second-tallest to meet, they must have the same parity. Treat those two as one and continue inductively.
Start with $n$ white points in a row. In each turn, let $L$ be the longest consecutive run of white points. A player may choose a prime length $P \le L/2$ and color such a run black. The player who cannot move loses. Given $n$, determine the outcome under optimal play.
For $n \ge 4$, the first player can color two or three middle points to leave identical parts on both sides, forcing a loss for the second player.
F. Monkeying Around
There are $N$ monkeys seated and telling jokes. Each joke has a type and range. When a monkey hears a joke it has not heard before, it leaves its seat; when it hears a familiar joke, it returns. Given all jokes, find how many monkeys are seated at the end.
Convert it into an interval problem: sort all left endpoints and right endpoints. For each monkey, maintain the jokes affecting that position; if the final joke occurs at least twice, the monkey is seated.
First count all rectangles. The number of rectangles of size $r \times c$ is $(N-r+1)(M-c+1)$; enumerate $r$ and $c$. $$ \sum_{r=1}^{N}\sum_{c=1}^{M}(N-r+1)(M-c+1) = \frac{(N+1)*N}{2}*\frac{(M+1)*M}{2} $$ Then use inclusion-exclusion: subtract rectangles containing one black cell, add those containing two, and so on.
To count rectangles containing $g$ black cells, compute the maximum and minimum $x,y$ coordinates: $maxx,maxy,minx,miny$. The result is $minx\cdot miny\cdot(N-maxx+1)\cdot(N-maxy+1)$.
boolcheck(char x) { return x == 'A' || x == 'H' || x == 'I' || x == 'M' || x == 'O' || x == 'T' || x == 'U' || x == 'V' || x == 'W' || x == 'X' || x == 'Y'; }
voidsolve() { memset(dp, -1, sizeof(dp)); scanf("%s", val + 1); int n = strlen(val + 1); //cout << n << endl; repp(i, 1, n) { if (check(val[i]))dp[i][i] = 1; } repp(i, 2, n) { if ((!check(val[i])) || (!check(val[i]))) { continue; } if (val[i] == val[i - 1])dp[i - 1][i] = 1; } for (int len = 3; len <= n; len++) { for (int st = 1; st <= n; st++) { int en = st + len - 1; if (en > n)continue; if ((!check(val[st])) || (!check(val[en]))) { dp[st][en] = -1; continue; } if (val[st] == val[en] && dp[st + 1][en - 1] != -1) { dp[st][en] = 1; } } } int maxx = 0; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { if (dp[i][j] == 1) { maxx = max(maxx, j - i + 1); } } } printf("%d\n", maxx); }
J. Lazy Physics Cat
A circle contains a triangle whose vertices are the center and two points on the circumference. Find the area of the sector after removing the triangle.
1 2 3 4 5 6 7 8 9 10 11 12 13
double len,a; voidsolve() { scanf("%lf%lf",&len,&a); double k =a; //cout<<a<<endl; a=a/180.0*PI; double all = PI*len*len*k/360; //printf("%lf\n",a); //printf("%lf\n",0.5*len*len*sin(a)); double res=all-0.5*len*len*sin(a); printf("%lf\n",res); }
K. Owl Geeks
By this point there had been too many easy problems. This one is also a direct simulation.
A LeetCode-style trapping-rain-water problem: given heights, find the water trapped in one dimension (there is also a 2D priority-queue version). With $Q$ queries, increase the height at position $X$ by $V$ and dynamically report the trapped water.
I thought about it for a long time, could not solve it, and looked at other solutions.
Maintain an increasing sequence from left to right to calculate water volume, and similarly from right to left.
After each update, inspect the relevant positions before and after it.
The complexity of this approach still feels a little mysterious to me.