UCV2013H - Slick

题意翻译

一片大小为 $n\times m$ 的海面发生了石油泄漏,石油表示为 $1$,海水表示为 $0$。 求石油组成的连通块总数,以及每种面积连通块的个数。 **本题多测** **【输入格式】** 对于每组测试数据,第一行两个整数 $n$ 和 $m$,表示海面的大小。 后跟一个 $n\times m$ 大小的字符矩阵,表示海面的石油泄漏情况。 当 $n = m = 0$ 时,终止程序。 **【输出格式】** 对于每组测试数据,第 $1$ 行输出一个整数 $k$,表示石油组成的连通块总数。 第 $2$ 至 $k$ 行每行两个整数 $i, j$,表示面积为 $i$ 的连通块有 $j$ 个。 **【数据范围及约定】** 对于 $100\%$ 的数据,$1 \le n, m\le250$。 Translated by @[159号程序员](https://www.luogu.com.cn/user/334586)。

题目描述

A maritime accident has caused oil to spill onto the seas of Felipistonia, which is a major natural disaster. The Felipistonia's government wants to clean up this mess before more damage occurs. To do this, they first have to know how serious was the accident and the amount of oil that has been spilled into the sea. The only instrument the Felipistonia's government has to get information of the magnitude of this disaster, is the use of satellite images. With these images they can estimate how much money they have to spend to clean this mess. For this, the number of slicks in the seas and the size of each slick must be know. A slick is a patch of oil floating on water. Unfortunately, the Felipistonia's people are not very bright, so they have hired you to help them process the image. An example of an image obtained by the satellites is shown in Figure 1(a). This image can be transformed to 0's and 1's as seen in Figure 1(b). Given this binary matrix, your job is to count the number of slicks in the ocean and their corresponding size. Two adjacent pixels in the image are considered to be in the same slick if they are in the same row or the same column. ![(a) A satellite image of the spilled oil. (b) The representation of the image in a binary matrix](https://cdn.luogu.com.cn/upload/vjudge_pic/SP15436/24b877f2290e86168568d449b806d33dd084fb11.png) Figure 1: (a) A satellite image of the spilled oil. (b) The representation of the image in a binary matrix

输入输出格式

输入格式


The input contains several test cases, each one corresponding to a different satellite image. The first line of each case contains two integers that indicate the number of rows (N) and columns (M) in the image (1 <= N, M <= 250). Then N lines follows with M integers each, containing the information of the image. The end of input is indicated by a test case with N = M = 0. This case should not be processed.

输出格式


For each image, output the number of slicks in the sea. Additionally, output the size of each slick in ascending order and the number of slicks of that size.

输入输出样例

输入样例 #1

10 10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 1 1 1
1 1 0 0 1 0 0 1 1 1
1 0 1 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
0 0

输出样例 #1

7
1 2
2 1
6 1
10 2
20 1