-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP657.cpp
71 lines (65 loc) · 1.27 KB
/
P657.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// map[y][x] walk.
void eatX(int x, int y, char map[][50], int W, int H) {
if('X' != map[y][x])
return;
map[y][x] = '*';
if(x > 0)
eatX(x-1, y, map, W, H);
if(x < W-1)
eatX(x+1, y, map, W, H);
if(y > 0)
eatX(x, y-1, map, W, H);
if(y < H-1)
eatX(x, y+1, map, W, H);
}
int getDice(int x, int y, char map[][50], int W, int H) {
if('.' == map[y][x])
return 0;
int ret = 0;
if('X' == map[y][x]) {
++ret;
eatX(x, y, map, W, H);
}
map[y][x] = '.';
if(x > 0)
ret += getDice(x-1, y, map, W, H);
if(x < W-1)
ret += getDice(x+1, y, map, W, H);
if(y > 0)
ret += getDice(x, y-1, map, W, H);
if(y < H-1)
ret += getDice(x, y+1, map, W, H);
return ret;
}
int main() {
int W, H;
char map[50][50];
string line;
for(int cas = 1; true; ++cas) {
cin >> W >> H;
if(W == 0 && H == 0)
return 0;
FORY(H) {
cin >> line;
FORX(W) {
map[y][x] = line[x];
}
}
vector<int> ret;
FORY(H) {
FORX(W) {
int cnt = getDice(x,y, map, W, H);
if(cnt > 0)
ret.push_back(cnt);
}
}
sort(ret.begin(), ret.end());
cout << "Throw " << cas << endl;
FORUI(ret.size()) {
if(i != 0)
cout << " ";
cout << ret[i];
}
cout << endl << endl;
} // for cas
}