The question seems to be very interesting.
Topic Analysis:
- The rooms are $1\times k$, which is a one-piece. This looks more obvious.
- A room if you want to cover a lattice $u$, then the area of the room is at least $dis (U, boundry) $, that is, its distance to the boundary, this seems to be more obvious appearance.
- The answer is at least $max \{dis (U, boundry) \}$ and can then be constructed to take the minimum value, that is, the answer is $max\{dis (U, boundry) \}$.
Algorithm Flow:
- Special sentence: If the input is an odd square with an edge length, and $ (x, y) $ happens to be the center of the square, the answer is $\frac{n-1}{2}$.
- Initialize: Because the answer is at least $\lfloor\frac{min (n,m) +1}{2}\rfloor$ (consider the most central lattice), the answer is initialized to this thing.
- Update answer: Then we just need to find $ (x, y) $ next to the four lattice, calculate its distance to the boundary, and then the initial answer to the maximum value is the final answer.
Some details:
- When enumerating the adjacent squares of $ (x, y) $, be aware that the lattice is legal.
- How to calculate $dis (U, boundry) $? Direct enumeration of the direction of expansion, see how many steps to reach the boundary, take its minimum number of steps.
- When calculating the distance, note that you can only expand from three directions, One Direction will go through $ (x, y) $, it is not moving.
Time complexity: $O (T) $, Space complexity: $O (1) $.
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 Const intfx[4][2] = {{1,0}, {-1,0}, {0,1}, {0, -1}};6 intN, m, x, y;7 8InlineintCalc (intTxintTyintk)9 {Ten intMin =min (n, m); One for(inti =0; I <4; i + +) A { - if(k = = i)Continue ; - if(i = =0) min = min (min, n +1-tx); the if(i = =1) Min =min (min, TX); - if(i = =2) min = min (min, M +1-ty); - if(i = =3) Min =min (min, ty); - } + returnMin; - } + AInlineintSolve () at { - if(n = = M && (N &1) && x = = y && (x *2-1==N)) - returnN-1>>1; - intans = min (n, m) +1>>1; - for(intK =0; K <4; K + +) - { in inttx = x + fx[k][0], Ty = y + fx[k][1]; - if(TX && Ty && TX <= n && ty <=m) toans = max (ans, Calc (tx, Ty, K ^1)); + } - returnans; the } * $ intMain ()Panax Notoginseng { - while(SCANF ("%d%d%d%d", &n, &m, &x, &y) = =4) theprintf"%d\n", Solve ()); + A return 0; the}
4302_gromah
Bzoj 4302 Buildings Problem Solving report