https://www.luogu.org/problem/show?pid=1101#sub
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int dx[]={0,1,1,1,0,0,-1,-1,-1},dy[]={0,1,0,-1,-1,1,1,-1,0};
int n;char a[200][200],table[]={'0','y','i','z','h','o','n','g'};
bool color[200][200];
bool judge(int x,int y)
{
if(x<=n&&x>=1&&y>=1&&y<=n) return 1;
return 0;
}
void dfs(int x,int y,int to,int k)
{
if(k==7)
{
color[x][y]=true;
for(int i=1;i<7;i++)
{
color[x-i*dx[to]][y-i*dy[to]]=true;
}
}
int xs=x+dx[to],ys=y+dy[to];
if(judge(xs,ys))
if(a[xs][ys]==table[k+1])
{
dfs(xs,ys,to,k+1);
}
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(a[i][j]=='y')
for(int o=1;o<=8;o++)
{
int xs=i+dx[o],ys=j+dy[o];
if(judge(xs,ys))
if(a[xs][ys]=='i')
{
dfs(xs,ys,o,2);
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(!color[i][j])
cout<<"*";
else cout<<a[i][j];
}
puts("");
}
return 0;
}