PersonalCorpus 版 (精华区)
1044406 Big Guava ... 469 Accepted 0:00.020
64 2002/08/27 06:49:53.368
char map[101][101],s[101];
int sum[101][101],i,j,k,n,m,p;
int st[10000][2];
int tot;
void tryit(int a, int b)
{
tot++;
st[tot][0]=a;
st[tot][1]=b;
map[a][b]='L';
if (a-1>=0) if (map[a-1][b]=='W') tryit(a-1,b);
if (b-1>=0) if (map[a][b-1]=='W') tryit(a,b-1);
if (a+1<n) if (map[a+1][b]=='W') tryit(a+1,b);
if (b+1<m) if (map[a][b+1]=='W') tryit(a,b+1);
if ((a-1>=0)&&(b-1>=0)) if (map[a-1][b-1]=='W') tryit(a-1,b-1);
if ((a+1<n)&&(b-1>=0)) if (map[a+1][b-1]=='W') tryit(a+1,b-1);
if ((a+1<n)&&(b+1<m)) if (map[a+1][b+1]=='W') tryit(a+1,b+1);
if ((a-1>=0)&&(b+1<m)) if (map[a-1][b+1]=='W') tryit(a-1,b+1);
}
void main()
{
scanf("%d\n",&k);
while (k>0) {
k--; n=0;
while (1) {
gets(s);
if (strlen(s)==0) break;
if (isalpha(s[0])) strcpy(map[n++],s); else break;
}
m=strlen(map[0]);
for (i=0;i<n;i++) for (j=0;j<m;j++)
if (map[i][j]=='W') {
tot=0;
tryit(i,j);
for (p=1;p<=tot;p++) sum[st[p][0]][st[p][1]]=tot;
}
while (sscanf(s,"%d%d",&i,&j)==2) {
printf("%d\n",sum[i-1][j-1]);
if (gets(s)==NULL) break;
}
// if (k>0) printf("\n");
printf("\n");
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.247毫秒