This is my blog.
背景:In a stroke of luck almost beyond imagination, Farmer John was sent a ticket to the Irish Sweepstakes (really a lottery) for his birthday. This ticket turned out to have only the winning number for the lottery! Farmer John won a fabulous castle in the Irish countryside.
Bragging rights being what they are in Wisconsin, Farmer John wished to tell his cows all about the castle. He wanted to know how many rooms it has and how big the largest room was. In fact, he wants to take out a single wall to make an even bigger room.
Your task is to help Farmer John know the exact room count and sizes.
The castle floorplan is divided into M (wide) by N (1 <=M,N<=50) square modules. Each such module can have between zero and four walls. Castles always have walls on their “outer edges” to keep out the wind and rain.
Consider this annotated floorplan of a castle:
题目:castle
输入:
The map is stored in the form of numbers, one number for each module, M numbers on each of N lines to describe the floorplan. The input order corresponds to the numbering in the example diagram above.
Each module number tells how many of the four walls exist and is the sum of up to four integers:
1: wall to the west
2: wall to the north
4: wall to the east
8: wall to the south
Inner walls are defined twice; a wall to the south in module 1,1 is also indicated as a wall to the north in module 2,1.
Line 1: Two space-separated integers: M and N
Line 2..: M x N integers, several per line.
输出:The output contains several lines:
my AC code:
|
|
官网题解
|
|
官网题解中对最后一句话的条件处理的很好,最后一句话Choose the optimal wall to remove from the set of optimal walls by choosing the module farthest to the west (and then, if still tied, farthest to the south). If still tied, choose 'N' before 'E'. Name that wall by naming the module that borders it on either the west or south, along with a direction of N or E giving the location of the wall with respect to the module.
,我理解了一个晚上,首先是farthest应翻译为最大程度上地
,而不是最远地
,其次不要漏条件,一个是要左下角,第二个是N比E更好,不可遗漏。
官网的代码还有一个优点(目前发现的),它发挥了c++的优点,面向对象,非常清晰。
一道简单dfs题,也学到了许多呢。
转载请注明出处,谢谢。
愿 我是你的小太阳