PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000009. Cảm biến kết nối (Sensors)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cảm biến kết nối (Sensors)
Sensors
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a grid with rows and columns. A cell marked # contains a sensor; a cell marked . is empty. Two sensors are directly connected if their cells share a side or a corner. Connections may also pass through other sensors. Count the connected groups of sensors.
Input
The first line contains two integers . Each of the next lines is a string of characters, each either # or ., describing one row.
Output
Print the number of connected groups of sensors.
Subtasks
- Subtask 1 (20 points): ; ; each cell contains
#or.. - Subtask 2 (30 points): ; ; each cell contains
#or.. - Subtask 3 (50 points): ; ; each cell contains
#or..
Examples
Input
5 6
.##...
...#..
....##
#.#...
..#...
Output
3
Explanation
The first group has cells (1,2),(1,3),(2,4),(3,5),(3,6); the second is (4,1), and the third is (4,3),(5,3). Hence 3 groups.