本地调试没问题但是只有第一个点AC
查看原帖
本地调试没问题但是只有第一个点AC
535224
nyllsom楼主2021/7/9 15:27
#include <bits/stdc++.h>
using namespace std;

int n;
char ma[105][105];
int vis[105][105];
int m, c[10010][2];
int xx[] = {1, -1, 1, -1, 1, -1,  0, 0};
int yy[] = {0, 0, 1, -1, -1, 1, 1, -1};
char t[] = "yizhong";
bool st;

bool dfs(int x, int y, int dir, int next) {
	if (next >= 7) {
		vis[x][y] = 1;
		return true;
	}
	int i, j;
	int tx = x + xx[dir], ty = y + yy[dir];
	if (tx >= 1 && tx <= n && ty >= 1 && ty <= n) {
		if (ma[tx][ty] == t[next]) {
			if (dfs(tx, ty, dir, next + 1)) {
				vis[x][y] = 1;
				return true;
			}
		}
	}
	return false;
} 

int main() {
	int i, j;
	cin >> n;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			cin >> ma[i][j];
			if (ma[i][j] == 'y') {
				c[++m][0] = i;
				c[m][1] = j;
			}
		}
	}
	for (i = 1; i <= m; i++) {
		for (j = 0; j < 8; j++) {
			if (dfs(c[i][0], c[i][1], j, 1)) {
				vis[i][j] = 1; 
			}

		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (vis[i][j]) {
				cout << ma[i][j];
			}
			else {
				cout << "*";
			}
		}
		cout << endl;
	}
	return 0;
}

如题,哪位大佬解答一下?

2021/7/9 15:27
加载中...