# 度度熊的01世界

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1389    Accepted Submission(s): 526

Problem Description

Input

Output

Sample Input
32 32 00000000000000000000000000000000 00000000000111111110000000000000 00000000001111111111100000000000 00000000001111111111110000000000 00000000011111111111111000000000 00000000011111100011111000000000 00000000111110000001111000000000 00000000111110000001111100000000 00000000111110000000111110000000 00000001111110000000111110000000 00000001111110000000011111000000 00000001111110000000001111000000 00000001111110000000001111100000 00000001111100000000001111000000 00000001111000000000001111000000 00000001111000000000001111000000 00000001111000000000000111000000 00000000111100000000000111000000 00000000111100000000000111000000 00000000111100000000000111000000 00000001111000000000011110000000 00000001111000000000011110000000 00000000111000000000011110000000 00000000111110000011111110000000 00000000111110001111111100000000 00000000111111111111111000000000 00000000011111111111111000000000 00000000111111111111100000000000 00000000011111111111000000000000 00000000001111111000000000000000 00000000001111100000000000000000 00000000000000000000000000000000 32 32 00000000000000000000000000000000 00000000000000001111110000000000 00000000000000001111111000000000 00000000000000011111111000000000 00000000000000111111111000000000 00000000000000011111111000000000 00000000000000011111111000000000 00000000000000111111110000000000 00000000000000111111100000000000 00000000000001111111100000000000 00000000000001111111110000000000 00000000000001111111110000000000 00000000000001111111100000000000 00000000000011111110000000000000 00000000011111111110000000000000 00000001111111111111000000000000 00000011111111111111000000000000 00000011111111111111000000000000 00000011111111111110000000000000 00000000001111111111000000000000 00000000000000111111000000000000 00000000000001111111000000000000 00000000000111111110000000000000 00000000000011111111000000000000 00000000000011111111000000000000 00000000000011111111100000000000 00000000000011111111100000000000 00000000000000111111110000000000 00000000000000001111111111000000 00000000000000001111111111000000 00000000000000000111111111000000 00000000000000000000000000000000 3 3 101 101 011

Sample Output
0 1 -1

Source

‘1’联通块的数量等于1且‘0’的联通快的数量为2，则为0

‘1’联通快的数量等于1且‘0’的联通块的数量为1，则为1

AC代码：

/**
* 行有余力，则来刷题！
* 博客链接:http://blog.csdn.net/hurmishine
* 个人博客网站:http://wuyunfeng.cn/
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=100+5;
char a[maxn][maxn];
bool vis[maxn][maxn];
int n,m;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
bool OK(int x,int y)
{
if(x<0||x>n+1||y<0||y>m+1)
return false;
return true;
}
void DFS(int x,int y)
{
vis[x][y]=true;
for(int i=0;i<4;i++)
{
int xx=x+dir[i][0];
int yy=y+dir[i][1];
if(OK(xx,yy)&&!vis[xx][yy]&&a[xx][yy]==a[x][y])
{
DFS(xx,yy);
}
}
}
int main()
{
//freopen("C:\\Users\\hncu_acm\\Desktop\\data.txt","r",stdin);
while(cin>>n>>m)
{
memset(a,'0',sizeof(a));
for(int i=1; i<=n; i++)
{
for(int j=1;j<=m;j++)
cin>>a[i][j];
}
memset(vis,false,sizeof(vis));
int zero=0,one=0;
for(int i=0;i<=n+1;i++)
{
for(int j=0;j<=m+1;j++)
{
if(!vis[i][j])
{
if(a[i][j]=='0')
zero++;
else
one++;
DFS(i,j);
}
}
}
//cout<<zero<<" "<<one<<endl;
if(zero==2&&one==1)
cout<<"0"<<endl;
else if(zero==1&&one==1)
cout<<"1"<<endl;
else
cout<<"-1"<<endl;
}
return 0;
}

#### HDU6113 度度熊的01世界(深搜DFS,2017"百度之星"程序设计大赛 - 初赛（A）)

2017-08-12 18:47:06

#### 【原创】【百度之星2017初赛A】1006 度度熊的01世界

2017-08-12 18:09:12

#### 2017百度之星初赛（A） 度度熊的01世界（BFS/DFS）

2017-08-12 21:04:50

#### 百度之星初赛（A）--度度熊的01世界----bfs搜索

2017-08-13 21:57:03

#### 2017百度之星资格赛：1001. 度度熊保护村庄（计算几何+最小环）

2017-08-07 16:52:34

#### 2017"百度之星"程序设计大赛 - 初赛（B）1005 度度熊的交易计划（【网络流】）

2017-09-06 19:47:58

#### 2017百度之星资格赛：1002. 度度熊的王国战略

2017-08-05 16:46:46

#### 2017百度之星资格赛题解

2017-08-05 17:49:00

#### 百度之星初赛（B）--度度熊的交易计划----最小费用最大流

2017-08-13 22:36:17

#### hdu 6113 度度熊的01世界/2017 百度之星

2017-08-12 17:31:54