Блог пользователя NeoYL

Автор NeoYL, история, 11 месяцев назад, По-английски

This is my personal note and might be some kind of user editorial/learning material for some people!

This is the sixth episode of this "note" series. I will write notes on problems (normally around 2400-ish problems), that are both interesting and educational. I normally will spend a few hours on each problem so please be patient when reading the blog.

If you want to motivate me to write a continuation (aka note 7), a significant upvote from you would be well appreciated! If I received lots of downvotes (because I'm also spending a lot of time to write this and to learn latex only to express my ideas accurately to you guys), I'm probably not gonna continuing writing these blogs.

Difficulty rating
Tags

Problem link

Problem paraphrased:

Given a $$$N*M$$$ grid. Cell '.' denotes an empty cell, '#' denotes a wall and 'V' would the the starting position.

An exit is a cell with $$$.$$$ and is at the edge of the grid.

Type 1: grids with $$$V$$$ not able to visit any exits.

Type 2: grids with $$$V$$$ only able to visit exactly one exit.

Type 3: grids with $$$V$$$ able to visit $$$\geq 2$$$ exits

Find maximum replacement (changing '.' to '#') such that the type of grid remains the same.

Again , try the problem first before continuing.

Clearly we can seperate into 3 cases:

Type 1 hint
Type 1
Type 2 hint
Type 2
Type 3 hint
Type 3

Phew, finally finished the problem~

Feelings

AC code link

The code looks slightly ugly, hope you guys can comprehend it.

Hope you guys learnt something from the blog. Thank you for reading.

  • Проголосовать: нравится
  • +38
  • Проголосовать: не нравится

»
11 месяцев назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

You can significantly shorten your code by using dx/dy arrays. (It also might be useful to create a vector storing all the pairs on the edge of the grid, since several times you iterate over these cells using four separate loops and having them in all place would allow you to stop writing the same code four times.)

  • »
    »
    11 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I do that often but here, I'm trying to show people what are my thinking processes. Maybe will look clearer for some people. Thanks for the advice anyways.