NeoYL's blog

By NeoYL, history, 12 months ago, In English

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.

  • Vote: I like it
  • +38
  • Vote: I do not like it

»
12 months ago, # |
  Vote: I like it +10 Vote: I do not like it

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.)

  • »
    »
    12 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.