样例过单全RE0求调
查看原帖
样例过单全RE0求调
1293918
CaoGenJY楼主2024/12/9 22:20
#include <bits/stdc++.h>
using namespace std;

int dx[10] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy[10] = {1, 1, 1, 0, -1, -1, -1, 0};
int n;
char m[1100][1100];
char ans[1100][1100];
char tar[10] = "yizhong";

bool dfs(int x, int y, int op, int depth){
	if(m[x][y] == 'g'){
		ans[x][y] = true;
		return true;
	}
	int xx = x + dx[op];
	int yy = y + dy[op];
	if(xx < 0 || xx >= n || yy < 0 || yy >= n) return false;
	if(m[xx][yy] != tar[depth + 1]) return false;
	if(dfs(xx, yy, op, depth + 1)) ans[xx][yy] = m[xx][yy];
}

int main(){
	memset(ans, '0', sizeof(ans));
	cin >> n;
	for(int i = 0; i < n; i ++ ){
			for(int j = 0; j < n; j ++ ){
				char c;
				cin >> c;
				m[i][j] = c;
			} 
		}
	for(int i = 0; i < n; i ++ ){
		for(int j = 0; j < n; j ++ ){
			if(m[i][j] == 'y'){
				for(int k = 0; k < 8; k ++ ){
					if(dfs(i, j, k, 0)) ans[i][j] = 'y';
				}
			}
		} 
	}
	for(int i = 0; i < n; i ++ ){
		for(int j = 0; j < n; j ++ ){
			if(ans[i][j] != '0') cout << ans[i][j];
			else cout << "*";
		}
		cout << endl;
	}
}
2024/12/9 22:20
加载中...