#include #include #include #include #include #define DBG printf int w, h; char fld [64][64]; int res[1024], nres; int qx[4096], qy[4096], qb, qe; int wx[4096], wy[4096], wb, we; int cmpint (const void* av, const void* bv) { int a = *(int*) av, b = *(int*) bv; return ( a < b ) ? -1 : +1; } void pque (int x, int y) { if ( x < 0 || x >= h || y < 0 || y >= w ) return; if ( fld[x][y] != 'X' ) return; wx[we] = x; wy[we++] = y; fld[x][y] = '*'; } void point (int x, int y) { wb = we = 0; wx[we] = x; wy[we++] = y; fld[x][y] = '*'; ++res[nres]; while ( wb < we ) { x = wx[wb]; y = wy [wb++]; pque (x+1, y); pque (x-1, y); pque (x, y+1); pque (x, y-1); } } void enque (int x, int y) { if ( x < 0 || x >= h || y < 0 || y >= w ) return; if ( fld[x][y] == 'X' ) point (x, y); if ( fld[x][y] != '*' ) return; qx[qe] = x; qy[qe++] = y; fld[x][y] = '.'; } void dice (int x, int y) { qb = qe = 0; qx[qe] = x; qy[qe++] = y; fld[x][y] = '.'; res[nres] = 0; while ( qb < qe ) { x = qx[qb]; y = qy [qb++]; enque (x+1, y); enque (x-1, y); enque (x, y+1); enque (x, y-1); } ++nres; } int main (void) { int prob = 0; FILE* fin = fopen ("dice.in", "r"); for ( ; ; ) { fscanf (fin, "%d%d\n", &w, &h); if ( w == 0 && h == 0 ) break; for ( int i = 0; i < h; ++i ) fgets (fld[i], 64, fin); nres = 0; for ( int i = 0; i < h; ++i ) for ( int j = 0; j < w; ++j ) if ( fld[i][j] == '*' ) dice (i, j); qsort (res, nres, sizeof (res[0]), cmpint); printf ("Throw %d\n%d", ++prob, res[0]); for ( int i = 1; i < nres; ++i ) printf (" %d", res[i]); printf ("\n\n"); } return 0; }