I am preparing for a programming competition, and I would like to know how I can solve this problem. I guess this is a geometry problem, and it seems like I can't figure out how to solve it.
There he is:
There is a courtyard in which there are wolves and sheep. There are also blocks in the yard that do not allow passage. Wolves are represented by "w" and sheep with "s", and blocks with "#", and the space in which everyone can move is ".". Thus, a possible input would look like this:
8 8 .######. #..s...# #.####.# #.#w.#.# #.#.s#s# #s.##..# #.w..w.# .######.
The 2 digits above the yard are rows x columns.
As you can see, different types of sectors can be formed in the yard. Here are two sectors:
There is a wolf in the first, and a sheep in the second. Since they are located in two different sectors (i.e. the Wolf cannot reach the sheep), he cannot eat it. If they were in the same sector, the wolf would eat sheep.
My question for you is this: given input like the above, how should I calculate how many sheep will survive? How can I imagine a βyardβ in C ++? What should the algorithm look like? Are there any materials for understanding such problems and problems?
Any help is appreciated. Thanks in advance.
source share