http://www.luogu.org/problem/show?pid=1101
循环找到一个y后向8个方向搜索,直到搜到g,然后按照方向反向填充即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
const int dx[8] = {0,1,0,-1,1,-1,-1,1},dy[8] = {1,0,-1,0,1,-1,1,-1};
const char ch[10] = "yizhong";
int n;
char map[105][105];
char ans[105][105];
int dfs(int x, int y, int dir, int times)
{int tx = x + dx[dir], ty = y + dy[dir];if (times==6) {int x1 = tx;int y1 = ty;while (times!=-1){ans[x1][y1] = ch[times];x1 -= dx[dir];y1 -= dy[dir];times--;}} elseif (tx>=0&&ty>=0&&tx<n&&ty<n&&ch[times]==map[tx][ty]){dfs(tx, ty, dir, times+1); }
}
int main()
{scanf("%d\n", &n);for (int i=0;i<n;i++)scanf("%s", &map[i]); for (int i=0;i<n;i++)for (int j=0;j<n;j++){ans[i][j] = '*';}for (int i=0;i<n;i++)for (int j=0;j<n;j++)if (map[i][j]=='y') for (int k=0;k<8;k++) dfs(i,j,k,1);for (int i=0;i<n;i++){for (int j=0;j<n;j++)putchar(ans[i][j]);putchar('\n');}return 0;
}