记录编号 |
103183 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[入门经典] 黑白图像 |
最终得分 |
100 |
用户昵称 |
noier |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.328 s |
提交时间 |
2014-05-24 21:41:44 |
内存使用 |
2.24 MiB |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
//////////////////////
FILE *in=fopen("common.in","r");
FILE *out=fopen("common.out","w");
const int size=710;
int map[size][size];
int count1=0;
/////////////////////
void work(int i,int j);
int main (){
freopen("common.in","r",stdin);
freopen("common.out","w",stdout);
memset(map,0,sizeof(map));
int n;
fscanf(in,"%d",&n);
//cout<<n<<endl;
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
int temp;
fscanf(in,"%1d",&temp);
map[i][j]=temp;
}
}
/*for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
cout<<map[i][j];
}
cout<<endl;
}
cout<<endl;*/
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
if(map[i][j]==1) {
work(i,j);
count1++;
/*for (int a=1;a<=n;a++){
for (int b=1;b<=n;b++){
cout<<map[a][b];
}
cout<<endl;
}
cout<<endl;*/
}
}
}
cout<<count1<<endl;
return 0;
}
void work(int i,int j){
if (map[i][j]==0) return;
else {
map[i][j]=0;
work(i-1,j-1);work(i-1,j);work(i-1,j+1);
work(i,j-1); work(i,j+1);
work(i+1,j-1);work(i+1,j);work(i+1,j+1);
}
}