#include #include #include #include #include static char F[550][550]; int dices[550*550],dicesN; static int found(int y,int x) { int dots=0; static int sea[10000][2],seaN; #define STEP(yn,xn) do { \ if (F[yn][xn]=='X') { \ sea[seaN][0]=y; \ sea[seaN][1]=x; \ seaN++; \ F[yn][xn]='*'; \ } \ } while (0) sea[0][0]=y; sea[0][1]=x; seaN=1; assert(F[y][x]=='X'); F[y][x]='*'; while (seaN) { y=sea[seaN-1][0]; x=sea[seaN-1][1]; seaN--; assert(F[y][x]=='*'); STEP(y-1,x); STEP(y+1,x); STEP(y,x-1); STEP(y,x+1); #undef STEP } return dots; } static int solvedice(int y,int x) { int dots=0; static int sea[10000][2],seaN; #define STEP(yn,xn) do { \ if (F[yn][xn]=='X') { \ found(yn,xn); \ dots++; \ assert(F[yn][xn]=='*'); \ } \ if (F[yn][xn]=='*') { \ sea[seaN][0]=yn; \ sea[seaN][1]=xn; \ seaN++; \ F[yn][xn]='>'; \ } \ } while (0) sea[0][0]=y; sea[0][1]=x; seaN=1; if (F[y][x]=='X') { found(y,x); dots++; } assert(F[y][x]=='*' || F[y][x]=='X'); F[y][x]='>'; while (seaN) { y=sea[seaN-1][0]; x=sea[seaN-1][1]; seaN--; assert(F[y][x]=='>'); STEP(y-1,x); STEP(y+1,x); STEP(y,x-1); STEP(y,x+1); #undef STEP } return dots; } static int int_compar(const int *ap,const int *bp) { return((*bp)-(*ap)); } int main(void) { int i; int H,W,y,y2; char *s; for (;;) { i=scanf("%d %d\n",&H,&W); assert(i==2); if (H==0 && W==0) break; for (y=1;y<=H;y++) { s=fgets(F[y]+1,sizeof(F[y])-2,stdin); assert(s); } dicesN=0; for (y=1;y<=H;y++) { while ((s=strchr(F[y]+1,'*'))) { dices[dicesN++]=solvedice(y,s-F[y]); #ifdef DEBUG for (y2=1;y2<=H;y2++) { fputs(F[y2]+1,stdout); } #endif } while ((s=strchr(F[y]+1,'X'))) { dices[dicesN++]=solvedice(y,s-F[y]); #ifdef DEBUG for (y2=1;y2<=H;y2++) { fputs(F[y2]+1,stdout); } #endif } } qsort(dices,dicesN,sizeof(*dices), (int (*)(const void *,const void *))int_compar); fputs("Throw:",stdout); for (i=0;i