Bzoj 4302 Buildings Problem Solving report

Source: Internet
Author: User

The question seems to be very interesting.

Topic Analysis:

    1. The rooms are $1\times k$, which is a one-piece. This looks more obvious.
    2. 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.
    3. 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:

    1. 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}$.
    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.
    3. 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:

    1. When enumerating the adjacent squares of $ (x, y) $, be aware that the lattice is legal.
    2. 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.
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.