标签:div highlight pac eof end space stream cin namespace
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char map[55][55];
int v[55][55];
int flag;
int n,m;
int dir [4][2]={0,1,1,0,0,-1,-1,0};
void dfs(int x,int y,int d,char f)
{
if(x>n||x<0||y<0||y>m||map[x][y]!=f)
{
return;
}
if(v[x][y]==1)
{
flag=1;
return;
}
v[x][y]=1;
for(int i=0;i<4;i++)
{
if (d==0&&i==2) continue;
if (d==1&&i==3) continue;
if (d==2&&i==0) continue;
if (d==3&&i==1) continue;
int dx=x+dir[i][0];
int dy=y+dir[i][1];
dfs(dx,dy,i,f);
}
}
int main()
{
while(cin>>n>>m)
{
memset(v,0,sizeof(v));
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>map[i][j];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(v[i][j]!=1)
{
dfs(i,j,-1,map[i][j]);
}
}
if(flag==1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
标签:div highlight pac eof end space stream cin namespace
原文地址:https://www.cnblogs.com/biubiuWham/p/10031461.html