比赛 |
20121016 |
评测结果 |
AWWWWWWWWW |
题目名称 |
家族 |
最终得分 |
10 |
用户昵称 |
feng |
运行时间 |
0.009 s |
代码语言 |
C++ |
内存使用 |
4.12 MiB |
提交时间 |
2012-10-16 21:34:30 |
显示代码纯文本
#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;
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",&n);
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 (i==n) 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<=s[i];j++)
if (f[i][j]==1){
head=1;
tail=1;
queue[head][1]=i;
queue[head][2]=j;
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[i])
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;
}