문제
Problem 1: Perimeter [Brian Dean, 2013]
Farmer John has arranged N hay bales
FJ notices that his hay bales all form one large connected region, meaning that starting from any bale, one can reach any other bale by taking a series of steps either north, south, east, or west onto directly adjacent bales. The connected region of hay bales may however contain "holes" -- empty regions that are completely surrounded by hay bales.
Please help FJ determine the perimeter of the region formed by his hay bales. Note that holes do not contribute to the perimeter.
PROBLEM NAME: perimeter
입력
* Line 1: The number of hay bales, N.
* Lines
출력
* Line 1: The perimeter of the connected region of hay bales.
예제1
8
10005 200003
10005 200004
10008 200004
10005 200005
10006 200003
10007 200003
10007 200004
10006 200005
14
INPUT DETAILS: The connected region consisting of hay bales looks like this:
XX
X XX
XXX
OUTPUT DETAILS:
The length of the perimeter of the connected region is 14 (for example, the left side of the region contributes a length of 3 to this total). Observe that the hole in the middle does not contribute to this number.