# 度度熊的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;
}

举报原因： 您举报文章：HDU 6113 度度熊的01世界【2017"百度之星"】【简单搜索判断联通块】 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)