#include <iostream>
#include <queue>
#include <string.h>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
struct node{
int x;
int y;
};
int n,m;
int xx[4]={1,0,-1,0};
int yy[4]={0,1,0,-1};
int maze[505][505];
bool visit[505][505];
int bfs(int x,int y){
int cnt = 1;
queue<node> Q;
visit[x][y] = 1;
node temp;
temp.x = x;
temp.y = y;
Q.push(temp);
while(!Q.empty()){
node top = Q.front();
Q.pop();
for(int i = 0;i < 4;i++){
temp.x = top.x + xx[i];
temp.y = top.y + yy[i];
if(temp.x < 0||temp.x >= n||temp.y < 0 || temp.y >= m) continue;
if(maze[temp.x][temp.y] == 0&&!visit[temp.x][temp.y]){
visit[temp.x][temp.y] = 1;
cnt++;
Q.push(temp);
}
}
}
return cnt;
}
bool isin(int x,int y){
if(maze[x][y] == 1||visit[x][y]) return false;
int f1,f2,f3,f4;
f1 = f2 = f3 = f4 = 0;
for(int i = 0;i < x;i++){
if(maze[i][y] == 1){f1 = 1 ; break;}
}
for(int i = x + 1;i < n;i++){
if(maze[i][y] == 1){f2 = 1 ; break;}
}
for(int i = 0;i < y;i++){
if(maze[x][i] == 1){f3 = 1 ; break;}
}
for(int i = y + 1;i < m;i++){
if(maze[x][i] == 1){f4 = 1 ; break;}
}
if(f1&&f2&&f3&&f4) return true;
else return false;
}
int main(){
int sum = 0;
cin >> n >> m;
char ch;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
cin >> ch;
if(ch == '0') maze[i][j] = 0;
else maze[i][j] = 1;
}
}
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
if(isin(i,j)){
sum += bfs(i,j);
}
}
}
cout << sum ;
}
by VOUSICA @ 2019-04-24 19:15:22
@[VOUSICA](/space/show?uid=201229) 要是过了样例代表AC,那是不是我输出样例就能AK IOI 。。。谁说的样例过了就对了
by ecnerwaIa @ 2019-04-24 19:35:50
@[千年之狐_天才](/space/show?uid=54113)
找到毛病了
刚才太急了 不好意思
by VOUSICA @ 2019-04-24 20:07:18
@[VOUSICA](/space/show?uid=201229) 没事,但是记住过了样例和AC天差地别
by ecnerwaIa @ 2019-04-24 20:33:36