2284. Rank The Languages

单点时限: 2.0 sec

内存限制: 256 MB

You might have noticed that English and Spanish are spoken in many areas all over the world. Now it would be nice to rank all languages according to the number of states where they are spoken.

You’re given a map which shows the states and the languages where they are spoken. Look at the following map:

ttuuttdd

ttuuttdd

uuttuudd

uuttuudd

The map is read like this: Every letter stands for a language and states are defined as connected areas with the same letter. Two letters are “connected” if one is at left, at right, above or below the other one. So in the above map, there are three states where the language “t” is spoken, three where “u” is spoken and one state where people speak “d”.

Your job is to determine the number of states for each language and print the results in a certain order.

输入格式

The first line contains the number of testcases N. Each testcase consists of a line with two numbers H and W, which are the height and the width of the map. Then follow H lines with a string of W letters. Those letters will only be lowercase letters from “a” to “z”.

输出格式

For each testcase print “World #n”, where n is the number of the testcase. After that print a line for each language that appears in the testcase which contains the language, a colon, a space and the number of states where that language is spoken. These lines have to be ordered decreasingly by the number of states. If two languages are spoken in the same number of states, they have to appear alphabetically, which means language “i” comes before language “q”, for example.

样例

Input
2
4 8
ttuuttdd
ttuuttdd
uuttuudd
uuttuudd
9 9
bbbbbbbbb
aaaaaaaab
bbbbbbbab
baaaaacab
bacccccab
bacbbbcab
bacccccab
baaaaaaab
bbbbbbbbb
Output
World #1
t: 3
u: 3
d: 1
World #2
b: 2
a: 1
c: 1

6 人解决,10 人已尝试。

7 份提交通过,共有 15 份提交。

7.0 EMB 奖励。

创建: 15 年,9 月前.

修改: 6 年,8 月前.

最后提交: 5 年,11 月前.

来源: Freshman Programming Contest

题目标签