记录编号 |
44443 |
评测结果 |
WWWWAWAWAA |
题目名称 |
家族 |
最终得分 |
40 |
用户昵称 |
feng |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
0.008 s |
提交时间 |
2012-10-18 19:45:38 |
内存使用 |
4.12 MiB |
显示代码纯文本
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
int n,i,j;
int xx[5]={0,1,0,-1,0};
int yy[5]={0,0,1,0,-1};
int s[200];
int head;
int tail,x,y,m;
char a[200][300];
int f[200][300];
int queue[60000][3];
int main()
{
freopen("family.in","r",stdin);
freopen("family.out","w",stdout);
scanf("%d",&n);
scanf("%c",&a[0][0]);
j=1;
scanf("%c",&a[0][j]);
for (i=1;i<=n;i++){
a[i][1]=a[i-1][j];
a[i-1][j]='/';
j=1;
while ((a[i][j]==' ') || (a[i][j]=='*') || (a[i][j]-'a'>=0 && a[i][j]-'a'<=25))
scanf("%c",&a[i][++j]);
while (a[i][j]!=' ' && a[i][j]!='*' && (a[i][j]-'a'<0 || a[i][j]-'a'>25)){
s[i]=j-1;
if (s[i]>m) m=s[i];
if (i==n) break;
if (feof(stdin)) break;
scanf("%c",&a[i][j]);
}
}
for (i=1;i<=n;i++){
for (j=1;j<=s[i];j++){
if (a[i][j]=='*' || a[i][j]==' ')
f[i][j]=-1;else
f[i][j]=1;
}
}
int ans=0;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (f[i][j]==1){
head=1;
tail=1;
queue[head][1]=i;
queue[head][2]=j;
f[i][j]=0;
while (head<=tail){
x=queue[head][1];
y=queue[head][2];
for (int k=1;k<=4;k++)
if (x+xx[k]>=1 && x+xx[k]<=n && y+yy[k]>=1 && y+yy[k]<=s[x+xx[k]])
if (f[x+xx[k]][y+yy[k]]==1){
f[x+xx[k]][y+yy[k]]=0;
queue[++tail][1]=x+xx[k];
queue[tail][2]=y+yy[k];
}
head++;
}
ans++;
}
printf("%d",ans);
return 0;
}