F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Islands

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 430    Accepted Submission(s): 33


Problem Description
There are so many islands in the sea. Some islands are enclosed by other ones. So, we can classify all the islands to several levels. An island has a level of 0 if it is contains no other islands. An island has a level of K+1 if it contains one or more islands and the highest level of the contained island(s) is K. Now, the map of the sea is given. Your task is to calculate the areas of islands in each level.
 

Input
The input contains several test cases. Each test case starts with a line contains two numbers N and M(1<=N<=100,1<=M<=100) which indicate the size of the map. The next N lines will contain M characters each to represent the map. Each character is either 'x' or '.'. A sea is defined as a maximal connected group of '.' cells, where two '.' cells are connected if they are vertically or horizontally adjacent. An island is defined as a maximal connected group of 'x' cells, where two 'x' cells are connected if they are vertically, horizontally, or diagonally adjacent. An island A contains island B if A and B are different and if you start sailing from any point of island B, you won't be able to sail out of island A.
 

Output
For each test case, output a single line with K+1 integers, where K is the highest level of an island in the map. The i-th number in the line is the total area of islands of level (i-1).
 

Sample Input
1 1 x 5 7 .xxxxx. x.....x x.x.x.x x.....x .xxxxx.
 

Sample Output
1 2 16
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.001000(s) query 1, Server time : 2025-04-01 07:00:23, Gzip enabled