#include<bits/stdc++.h>
using namespace std;
int H,L,ans;
char m[60][60];
int x[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};
void dfsx(int h,int l) {
for(int i=0; i<4; i++) {
int hh=h+x[i][0],ll=l+x[i][1];
if(hh>=0&&hh<H&&ll>=0&&ll<L&&m[hh][ll]=='X') {
m[hh][ll]='*';
dfsx(hh,ll);
}
}
}
void dfs(int h,int l) {
for(int i=0; i<4; i++) {
int hh=h+x[i][0],ll=l+x[i][1];
if(hh>=0&&hh<H&&ll>=0&&ll<L&&m[hh][ll]!='.') {
if(m[hh][ll]=='X') {
m[hh][ll]='*';
ans++;
dfsx(hh,ll);
}
m[hh][ll]='.';
dfs(hh,ll);
}
}
}
int main() {
int k=1;
while(scanf("%d%d",&L,&H),H) {
vector<int> r;
for(int i=0; i<H; i++) {
for(int j=0; j<L; j++) {
scanf(" %c",&m[i][j]);
}
}
for(int i=0; i<H; i++) {
for(int j=0; j<L; j++) {
if(m[i][j]=='*') {
ans=0;
m[i][j]='.';
dfs(i,j);
r.push_back(ans);
}
}
}
printf("Throw %d\n",k++);
sort(r.begin(),r.end());
for(int i=0; i<r.size(); i++) {
printf("%d ",r[i]);
}
printf("\n\n");
}
}
POJ The Die Is Cast
最新推荐文章于 2020-08-09 11:38:15 发布