題目來源:judgegirl from ntu prof. pangfeng Liu
Task Description
Write a function to determine the number and types of intersections in a city. We use a by integer array to represent a city. A one in the array indicates a road, and a zero in the array indicates a building. There are four kinds of intersection of roads.
- A cell is an intersection if it is one, and all of its four neighbors are also one.
- A cell is a T-junction if it is and exactly three of its neighbors are .
- A cell is a turn if it is and exactly two of its neighbors are , and these two neighbors do not form a straight line that goes through the cell.
- A cell is a dead end if it is , and exactly one of its neighbors is . Now given the matrix, please compute the number of intersections, -junctions, turns and dead ends.
Limits
is no more than .
Input Format
There are lines in the input. The first line has . Each of the next lines has integers. These integers are either or .
Output Format
There are four lines in the output. These four lines has the number of intersections, T-junctions, turns and dead ends, respectively.
Sample Input
5
1 1 1 1 1
1 0 1 0 1
1 1 1 1 1
1 0 1 0 1
1 1 1 0 1
Sample Output
1
3
4
1