全体目光向我看齐(深搜电子鼠)
  • 板块灌水区
  • 楼主White_Falcon
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/5/19 19:35
  • 上次更新2024/5/19 21:25:29
查看原帖
全体目光向我看齐(深搜电子鼠)
1003209
White_Falcon楼主2024/5/19 19:35

小发明:

迷宫区:

#include <bits/stdc++.h>
#include <windows.h>
using namespace std;

int n = 10;
char a[25][25];
bool vis[25][25];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void print(int x, int y){
	system("cls");
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i == x && j == y)cout << 'A';
			else cout << a[i][j];
		}cout << "\n";
	}
}

void dfs(int x, int y){
	if(x == n && y == n){
		print(x, y);
		Sleep(1000);
		cout << "YES\n";
		Sleep(10000000);
		return;
	}
	for(int i = 0; i < 4; i++){
		print(x, y);
		Sleep(600);
		int wx = x + dx[i], wy = y + dy[i];
		if(wx > n || wy > n || wx < 1 || wy < 1 || a[wx][wy] == '#' || vis[wx][wy]){
			continue;
		}
		vis[wx][wy] = 1;
		dfs(wx, wy);
		vis[wx][wy] = 0;
	}
	cout << "NO\n";
}

int main(){
	for(int i = 1; i <= n; i++){
		cin >> a[i] + 1;
	}
	dfs(1, 1);
	
	return 0;
} 

地图生成:

#include <bits/stdc++.h>
using namespace std;

int main(){
	freopen(".out", "w", stdout);
	srand((int)time(0));
	for(int i = 1; i <= 10; i++){
		for(int j = 1; j <= 10; j++){
			int x = rand() % 7;
			if(x == 1 || x == 3 || x == 5 || x == 6 || x == 0)cout << '.';
			else cout << '#';
		}cout << "\n";
	}
	return 0;
}

各位大佬觉得怎么样?

2024/5/19 19:35
加载中...