然而我就是对的......你这个数据不怎么强
by Access_Denied @ 2017-09-18 20:20:52
```cpp
#include<iostream>
#include<cstdio>
using namespace std;
int n;
char map[35][35]={'0'};
int re[35][35]={0};
int re1[35][35]={0};
int hen[9]={0,0,0,-1,1};
int shu[9]={0,1,-1,0,0};
void bfs(int x,int y)
{
for(int i=1;i<=4;i++)
{
if((x+hen[i]>=0&&y+shu[i]>=0&&x+hen[i]<=n+1&&y+shu[i]<=n+1)&&re1[x+hen[i]][y+shu[i]]!=1)
{
if(map[x][y]=='1')
{
re[x][y]=1;
re1[x][y]=1;
if(map[x+hen[i]][y+shu[i]]=='1')
{
bfs(x+hen[i],y+shu[i]);
}
continue;
}
re[x+hen[i]][y+shu[i]]=1;
re1[x+hen[i]][y+shu[i]]=1;
bfs(x+hen[i],y+shu[i]);
re1[x+hen[i]][y+shu[i]]=0;
}
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
for(int h=1;h<=n;h++)
{
cin>>map[i][h];
}
}
bfs(0,0);
for(int i=1;i<=n;i++)
{
for(int h=1;h<=n;h++)
{
if(re[i][h]==0)
{
map[i][h]='2';
}
cout<<map[i][h]<<' ';
}
cout<<endl;
}
return 0;
}
```
by GavinZheng @ 2017-10-15 12:58:00
我的DFS代码是对的,但是第四个点一直TLE
by GavinZheng @ 2017-10-15 12:58:26