内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

C++解迷宮問題-創(chuàng)新互聯(lián)

#include <iostream>
using namespace std;
#include <stack>
#include <assert.h>

//初始化迷宮
void InitMaze(int* maze,int row, int col)
{
	FILE* fout = fopen("Maze.txt", "r");

	assert(fout);

	for (int i = 0; i < row; ++i)
	{
		for (int j = 0; j < col;)
		{
			char ch = fgetc(fout);

			if (ch == EOF)
			{
				cout<<"Init MazeMap fail"<<endl;
				exit(false);
			}

			if (ch == '1' || ch == '0')
			{
				maze[i * row + j] = ch - '0';
				++j;
			}
		}
	}

	fclose(fout);
}

struct Pos
{
	int _row; //行
	int _col; //列
};

//打印迷宮
void PrintMaze(int* maze, int row, int col)
{
	for (int i = 0; i < row; ++i)
	{
		for (int j = 0; j < col; ++j)
		{
			cout<<maze[i * row + j]<<" ";
		}

		cout<<endl;
	}

	cout<<endl;
}

//判斷當前位置是否為0
inline bool CheckIsPassWay(int* maze, int row, int col, Pos pos)
{
	if (pos._row < row && pos._col < col
		&& maze[pos._row * col + pos._col] == 0)
	{
		return true;
	}

	return false;
}

//判斷迷宮是否有出口
bool GetMazePath(int* maze, int row, int col, Pos entry, stack<Pos>& path)
{
	assert(maze);

	path.push(entry);
	maze[entry._row * col + entry._col] = 2;//將走過的路標記為2

	while (!path.empty())
	{
		Pos cur = path.top();
		Pos next = cur;

		if (row-1 == next._row)//找到出口
		{
			return true;
		}

		//判斷右邊是否為0 
		next = cur;
		next._col++;
		if (CheckIsPassWay(maze, row, col, next))
		{
			maze[next._row * row + next._col] = 2;
			path.push(next);
			continue;
		}

		//上
		next = cur;
		next._row--;
		if (CheckIsPassWay(maze, row, col, next))
		{
			maze[next._row * row + next._col] = 2;
			path.push(next);
			continue;
		}

		//下
		next = cur;
		next._row++;
		if (CheckIsPassWay(maze, row, col, next))
		{
			maze[next._row * row + next._col] = 2;
			path.push(next);
			continue;
		}

		//左
		next = cur;
		next._col--;
		if (CheckIsPassWay(maze, row, col, next))
		{
			maze[next._row * row + next._col] = 2;
			path.push(next);
			continue;
		}

		path.pop();//四個方向都不通,返回上一步
	}

	return false;//棧為空,沒有找到出口
}


void TestMaze()
{
	int maze[10][10] = {};
	Pos entry = {1, 0};
	stack<Pos> path;//將走過的路徑保存在棧path中
	InitMaze((int*)maze, 10, 10);
	PrintMaze((int*)maze, 10, 10);
	GetMazePath((int*)maze, 10, 10, entry, path);
	PrintMaze((int*)maze, 10, 10);
}

int main()
{
	TestMaze();
	return 0;
}

C++解迷宮問題

成都創(chuàng)新互聯(lián)服務項目包括鄆城網(wǎng)站建設、鄆城網(wǎng)站制作、鄆城網(wǎng)頁制作以及鄆城網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網(wǎng)行業(yè)的解決方案,鄆城網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到鄆城省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

當前文章:C++解迷宮問題-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://m.rwnh.cn/article2/dcehoc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供建站公司、軟件開發(fā)外貿(mào)建站、ChatGPT定制開發(fā)、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)
湟中县| 农安县| 宜春市| 两当县| 光山县| 陆川县| 综艺| 阿荣旗| 禄劝| 陈巴尔虎旗| 枣强县| 仁化县| 巴林左旗| 潮安县| 永定县| 玉溪市| 剑阁县| 清丰县| 安溪县| 齐河县| 成武县| 崇义县| 哈密市| 察雅县| 延边| 吴堡县| 临夏县| 玛曲县| 东乡族自治县| 卢湾区| 长子县| 平阳县| 襄城县| 分宜县| 桐庐县| 临西县| 泗水县| 肥西县| 宜宾市| 启东市| 天柱县|