【C++学习第17天】深度有限搜索
创始人
2024-11-14 21:06:58
0

一、题目

AcWing 845. 八数码 - AcWing

二、代码

来自acwing

#include  #include  #include  #include   using namespace std;  typedef pair PII;  const int N = 110;  int n, m; int g[N][N]; int d[N][N]; PII q[N * N];  int bfs() { 	int hh = 0, tt = 0; 	q[0] = {0, 0};  	memset(d, -1, sizeof d); 	d[0][0] = 0;  	int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};  	while(hh <= tt) 	{ 		auto t = q[hh++];  		for(int i = 0; i < 4; i++){ 			int x = t.first + dx[i], y = t.second + dy[i]; 			if(x >= 0 && x < n && y >= 0 && y < m && g[x][y] == 0 && d[x][y] == -1){ 				d[x][y] = d[t.first][t.second] + 1; 				q[++tt] = {x, y}; 			} 		} 	} 	return d[n - 1][m - 1]; }   int main() { 	cin >> n >> m;  	for(int i = 0; i < n; i++) 		for(int j = 0; j < m; j++) 			cin >> g[i][j]; 	 	cout << bfs() << endl; 	return 0; }

相关内容

热门资讯

wepoker辅助器下载!智星... wepoker辅助器下载!智星菠萝有挂吗(透视)真是是真的有挂(扑克教程)1、实时wepoker辅助...
透视辅助!hhpoker俱乐部... 透视辅助!hhpoker俱乐部靠谱吗(辅助挂)一直真的是有挂(详细辅助教你攻略)1)hhpoker俱...
透视最新!aapoker透视方... 透视最新!aapoker透视方法,wepoker辅助器透视挂(详细辅助线上教程);原来确实真的有挂(...
透视苹果版!wepoekr底牌... 透视苹果版!wepoekr底牌透视,wpk辅助插件叫什么,微扑克教程(有挂插件);1、每一步都需要思...
wpk辅助工具!wepoker... wpk辅助工具!wepoker透视脚本网页(透视)一贯是有挂(技巧教程)1、点击下载安装,wepok...
透视辅助!微信微乐有挂没有(辅... 透视辅助!微信微乐有挂没有(辅助挂)切实是真的有挂(详细辅助揭秘攻略);一、微信微乐有挂没有AI软件...
透视实锤!WePoKer有没有... 透视实锤!WePoKer有没有透视挂,捕鱼辅助软件通用版(详细辅助新2025教程)科技教程也叫必备教...
透视辅助!wepoker底牌透... 透视辅助!wepoker底牌透视脚本http,德普之星辅助功能如何打开,2025新版教程(有挂技巧)...
透视辅助!丽水都来脚本辅助(辅... 透视辅助!丽水都来脚本辅助(辅助挂)真是真的有挂(详细辅助辅助教程);1、丽水都来脚本辅助ai机器人...
hhpoker辅助软件!we ... hhpoker辅助软件!we poker辅助器(透视)都是存在有挂(教你攻略);hhpoker辅助软...