主頁 > 後端開發 > A*演算法(超級詳細講解,附有舉例的詳細手寫步驟)

A*演算法(超級詳細講解,附有舉例的詳細手寫步驟)

2020-11-18 16:51:08 後端開發

背景:專案需要接觸此演算法,以下是一些自學成果,如有不足之處,歡迎指出,必虛心接受,做了一份PPT來匯報,此處直接使用自己PPT的截圖,部分圖片來源網路,如有侵權立馬洗掉,以下博文僅作為學習筆記,

目錄

A*尋路演算法

A*演算法解決什么問題

A*演算法的基本原理

A*演算法的詳細原理

A*演算法的詳細原理之定義

?A*演算法的詳細原理之初始設定

?A*演算法的詳細原理之尋路原理

A*演算法的詳細原理之結束條件

A*演算法的尋路詳細步驟

A*演算法的舉例說明

A*演算法的偽代碼

A*演算法的定義偽代碼 (C++)

A*演算法的尋路偽代碼(C++)

Python+PyQt代碼實作

代碼內容(可運行)

運行結果

可執行檔案


A*尋路演算法

A*演算法解決什么問題

A*演算法的基本原理

A*演算法的詳細原理

A*演算法的詳細原理之定義

A*演算法的詳細原理之初始設定

A*演算法的詳細原理之尋路原理

A*演算法的詳細原理之結束條件

A*演算法的尋路詳細步驟

S(start)起點 E(End)終點

A*演算法的舉例說明

如果還不懂的話,可以參考我手寫的計算步驟,再不懂可以私信我,(手稿字有點丑)

A*演算法的偽代碼

A*演算法的定義偽代碼 (C++)

//定義
int G;// 表示從起點 A 移動到網格上指定方格的移動耗費 (上下左右,還可沿斜方向移動)
int old_G;//舊G 第一次:從起點 A 直接移動到 A 四周方格的移動耗費 ;上次更新得到的G 
int new_G; //新G  從起點 A 經過當前搜索中心點到其四周指定點的移動耗費 
int H;//表示從指定的方格移動到終點 B 的預計耗費 (H 有很多計算方法, 這里我們設定只可以上下左右移動)
int F=G+H;//表示該點的總耗費
int open_list//一個記錄下所有被考慮來尋找最短路徑的格子
int close_list //一個記錄下不會再被考慮的格子
typedef struct point{
	bool Is_Wall;
	struct point* father;//父節點
}Point;
point* start_point;
point* end_point
point* min_point; 
point* now_point; 

A*演算法的尋路偽代碼(C++)

//FindPath
do{
	//確定中心搜索點,上一個中心點關閉,新的中心點開啟 
	查找:Find the minimumm "point" of "F" from the "open_list" center
	"now_point" = "min_point";//minimumm point 
	"now_point"添加到"close_list";
	
	//新中心點的周圍點開啟,新中心點關閉 
	回圈遍歷:"now_point"相鄰的周圍8格"s_now_point"中的每一個
	//這一塊它指的就是now_point周圍8點當前搜索點 s_now_point,為了簡單直接用它表示 
	if (它不可通過||它已經在"close_list"中){
		什么也不做;
	} else if (它不在開啟串列中){
		把它添加進"open_list";
		把"now_point"作為這它的"father",計算它的"F","G","H";
	}else if (它已經在開啟串列中){//通過G來判斷是否需要更新 
		if (new_G < old_G){
			更新它的"father"為當前中心搜索點"now_point";
			更新它的"G"與"F" ;
		} else{
			不更新,保持原來的"father", "G"與"F" ;
		} 
	}
} while(目標格"end_point"已經在"open_list"||"open_list"==NULL)
//存在路徑:目標格"end_point"已經在"open_list"
//不存在路徑: "open_list"==NULL,搜索了所有可能的點 

Python+PyQt代碼實作

代碼內容(可運行)

import time,sys
from PyQt5.QtWidgets import QDialogButtonBox,QDialog,QMainWindow,QGridLayout,QTextEdit,QLineEdit,QWidget, QMessageBox, QApplication,QLabel,QPushButton,QHBoxLayout,QVBoxLayout
from PyQt5.QtCore import Qt,QTimer,QObject,pyqtSignal,QBasicTimer
from PyQt5.QtGui import QPainter, QColor, QFont,QPen
import json
class config:
	WIDTH=20#地圖列數
	HEIGHT=20#地圖行數
	blockLength=30#繪制畫面時每一個節點方塊的邊長
class point:#點類(每一個唯一坐標只有對應的一個實體)
	_list=[]#儲存所有的point類實體
	_tag=True#標記最新創建的實體是否為_list中的已有的實體,True表示不是已有實體
	def __new__(cls,x,y):#重寫new方法實作對于同樣的坐標只有唯一的一個實體
		for i in point._list:
			if i.x==x and i.y==y:
				point._tag=False
				return i
		nt=super(point,cls).__new__(cls)
		point._list.append(nt)
		return nt
	def __init__(self,x,y):
		if point._tag:
			self.x=x
			self.y=y
			self.father=None
			self.F=0#當前點的評分  F=G+H
			self.G=0#起點到當前節點所花費的消耗
			self.cost=0#父節點到此節點的消耗
		else:
			point._tag=True
	@classmethod
	def clear(cls):#clear方法,每次搜索結束后,將所有點資料清除,以便進行下一次搜索的時候點資料不會沖突,
		point._list=[]
	def __eq__(self,T):#重寫==運算以便實作point類的in運算
		if type(self)==type(T):
			return (self.x,self.y)==(T.x,T.y)
		else:
			return False
	def __str__(self):
		return'(%d,%d)[F=%d,G=%d,cost=%d][father:(%s)]'%(self.x,self.y,self.F,self.G,self.cost,str((self.father.x,self.father.y)) if self.father!=None else 'null')
class A_Search:#核心部分,尋路類
	def __init__(self,arg_start,arg_end,arg_map):
		self.start=arg_start#儲存此次搜索的開始點
		self.end=arg_end#儲存此次搜索的目的點
		self.Map=arg_map#一個二維陣列,為此次搜索的地圖參考
		self.open=[]#開放串列:儲存即將被搜索的節點
		self.close=[]#關閉串列:儲存已經搜索過的節點
		self.result=[]#當計算完成后,將最終得到的路徑寫入到此屬性中
		self.count=0#記錄此次搜索所搜索過的節點數
		self.useTime=0#記錄此次搜索花費的時間--在此演示中無意義,因為process方法變成了一個逐步處理的生成器,統計時間無意義,
		#開始進行初始資料處理
		self.open.append(arg_start)
	def cal_F(self,loc):
		print('計算值:',loc)
		G=loc.father.G+loc.cost
		H=self.getEstimate(loc)
		F=G+H
		print("F=%d G=%d H=%d"%(F,G,H))
		return {'G':G,'H':H,'F':F}
	def F_Min(self):#搜索open串列中F值最小的點并將其回傳,同時判斷open串列是否為空,為空則代表搜索失敗
		if len(self.open)<=0:
			return None
		t=self.open[0]
		for i in self.open:
			if i.F<t.F:
				t=i
		return t
	def getAroundPoint(self,loc):#獲取指定點周圍所有可通行的點,并將其對應的移動消耗進行賦值,
		l=[(loc.x,loc.y+1,10),(loc.x+1,loc.y+1,14),(loc.x+1,loc.y,10),(loc.x+1,loc.y-1,14),(loc.x,loc.y-1,10),(loc.x-1,loc.y-1,14),(loc.x-1,loc.y,10),(loc.x-1,loc.y+1,14)]
		for i in l[::-1]:
			if i[0]<0 or i[0]>=config.HEIGHT or i[1]<0 or i[1]>=config.WIDTH:
				l.remove(i)
		nl=[]
		for i in l:
			if self.Map[i[0]][i[1]]==0:
				nt=point(i[0],i[1])
				nt.cost=i[2]
				nl.append(nt)
		return nl

	def addToOpen(self,l,father):#此次判斷的點周圍的可通行點加入到open串列中,如此點已經在open串列中則對其進行判斷,如果此次路徑得到的F值較之之前的F值更小,則將其父節點更新為此次判斷的點,同時更新F、G值,
		for i in l:
			if i not in self.open:
				if i not in self.close:
					i.father=father
					self.open.append(i)
					r=self.cal_F(i)
					i.G=r['G']
					i.F=r['F']
			else:
				tf=i.father
				i.father=father
				r=self.cal_F(i)
				if i.F>r['F']:
					i.G=r['G']
					i.F=r['F']
					# i.father=father
				else:
					i.father=tf
	def getEstimate(self,loc):#H :從點loc移動到終點的預估花費
		return (abs(loc.x-self.end.x)+abs(loc.y-self.end.y))*10
	def DisplayPath(self):#在此演示中無意義
		print('搜索花費的時間:%.2fs.迭代次數%d,路徑長度:%d'%(self.useTime,self.count,len(self.result)))
		if self.result!=None:
			for i in self.result:
				self.Map[i.x][i.y]=8
			for i in self.Map:
				for j in i:
					if j==0:
						print('%s'%'□',end='')
					elif j==1:
						print('%s'%'▽',end='')
					elif j==8:
						print('%s'%'★',end='')
				print('')
		else:
			print('搜索失敗,無可通行路徑')
	def process(self):#使用yield將process方法變成一個生成器,可以逐步的對搜索程序進行處理并回傳關鍵資料
		while True:
			self.count+=1
			tar=self.F_Min()#先獲取open串列中F值最低的點tar
			if tar==None:
				self.result=None
				self.count=-1
				break
			else:
				aroundP=self.getAroundPoint(tar)#獲取tar周圍的可用點串列aroundP
				self.addToOpen(aroundP,tar)#把aroundP加入到open串列中并更新F值以及設定父節點
				self.open.remove(tar)#將tar從open串列中移除
				self.close.append(tar)#已經迭代過的節點tar放入close串列中
				if self.end in self.open:#判斷終點是否已經處于open串列中
					e=self.end
					self.result.append(e)
					while True:
						e=e.father
						if e==None:
							break
						self.result.append(e)
					yield (tar,self.open,self.close)
					break

			# self.repaint()
			# print('回傳')
			yield (tar,self.open,self.close)
			time.sleep(5)#暫停
		self.useTime=time2-time1
class GameBoard(QMainWindow):#可視化類,pyqt5進行撰寫,
	def __init__(self):
		print('初始化地圖...')
		self.Map=[]
		for i in range(config.HEIGHT):
			col=[]
			for j in range(config.WIDTH):
				col.append(0)
			self.Map.append(col)
		self.startPoint=None
		self.endPoint=None
		self.search=None
		self.centerTimer=None
		self.yi=None
		self.special=None
		self.displayFlush=False
		super().__init__()
		print('初始化UI...')
		self.initUI()
	def initUI(self):
		#開始初始化UI部分
			#創建UI控制元件
		self.label_tips=QLabel("<p style='color:green'>使用說明:</p>右鍵單擊格子選定起始點,左鍵格子選定格子為墻壁或洗掉墻壁,\n<p style='color:green'>顏色說明:</p>\n黃色代表起點,綠色代表終點,黑色代表墻壁,紅色代表待搜索的open串列,灰色代表已搜索過的close串列,藍色代表當前搜索到的路徑",self)
		self.label_display=QLabel("",self)
		self.button_start=QPushButton("開始搜索",self)
		self.button_clearSE=QPushButton("重選起始點",self)
		self.button_clearWall=QPushButton("清空地圖墻壁",self)
		self.button_saveMap=QPushButton("保存地圖",self)
		self.button_loadMap=QPushButton("加載地圖",self)


			#設定控制元件屬性
		self.label_tips.setWordWrap(True)
		self.label_display.setWordWrap(True)
			#設定控制元件樣式
		self.label_display.setStyleSheet("border:1px solid black")
		self.label_display.setAlignment(Qt.AlignLeft)
		self.label_display.setAlignment(Qt.AlignTop)
			#設定控制元件的尺寸和位置
		self.label_tips.resize(200,150)
		self.button_saveMap.resize(80,30)
		self.button_loadMap.resize(80,30)
		self.label_display.resize(200,300)

		self.label_tips.move(100+(config.WIDTH-1)*config.blockLength,0)
		self.label_display.move(100+(config.WIDTH-1)*config.blockLength,400)
		self.button_start.move(100+(config.WIDTH-1)*config.blockLength,200)
		self.button_clearSE.move(100+(config.WIDTH-1)*config.blockLength,250)
		self.button_clearWall.move(100+(config.WIDTH-1)*config.blockLength,300)
		self.button_saveMap.move(100+(config.WIDTH-1)*config.blockLength,350)
		self.button_loadMap.move(200+(config.WIDTH-1)*config.blockLength,350)
			#給控制元件系結事件
		self.button_start.clicked.connect(self.button_StartEvent)
		self.button_clearSE.clicked.connect(self.button_Clear)
		self.button_clearWall.clicked.connect(self.button_Clear)
		self.button_saveMap.clicked.connect(self.button_SaveMap)
		self.button_loadMap.clicked.connect(self.button_LoadMap)
		#UI初始化完成
		self.setGeometry(0, 0, 150+(config.WIDTH*config.blockLength-config.blockLength)+200, 150+(config.HEIGHT*config.blockLength-config.blockLength))
		self.setMinimumSize(150+(config.WIDTH*config.blockLength-config.blockLength)+200, 150+(config.HEIGHT*config.blockLength-config.blockLength))
		self.setMaximumSize(150+(config.WIDTH*config.blockLength-config.blockLength)+200, 150+(config.HEIGHT*config.blockLength-config.blockLength))
		self.setWindowTitle('A*搜索')
		self.show()
	def addDisplayText(self,text):
		if self.displayFlush:
			self.label_display.setText(text+'\n')
			self.displayFlush=False
		else:
			self.label_display.setText(self.label_display.text()+text+'\n')
	def mousePressEvent(self,event):
		x,y=event.x()-50,event.y()-50
		x=x//config.blockLength
		y=y//config.blockLength
		if x>=0 and x<config.WIDTH and y>=0 and y<config.HEIGHT:
			if event.button()==Qt.LeftButton:
				if (x,y)!=self.startPoint and (x,y)!=self.endPoint:
					self.Map[y][x]=(1 if self.Map[y][x]==0 else 0)
			if event.button()==Qt.RightButton:
				if self.Map[y][x]==0:
					if self.startPoint==None:
						self.startPoint=(x,y)
						self.addDisplayText('添加了一個起點:(%d,%d)'%(x,y))
					elif self.endPoint==None and self.startPoint!=(x,y):
						self.endPoint=(x,y)
						self.addDisplayText('添加了一個終點:(%d,%d)'%(x,y))
			self.repaint()
	def button_StartEvent(self):
		sender=self.sender()
		print(sender)
		if self.startPoint!=None and self.endPoint!=None:
			if self.centerTimer==None:
				self.centerTimer=QBasicTimer()
			self.button_start.setEnabled(False)
			self.button_clearSE.setEnabled(False)
			self.button_clearWall.setEnabled(False)
			self.centerTimer.start(200,self)
			self.search=A_Search(point(self.startPoint[1],self.startPoint[0]),point(self.endPoint[1],self.endPoint[0]),self.Map)
			self.yi=self.search.process()
			self.addDisplayText('開始進行搜索')
	def button_SaveMap(self):
		with open('map.txt','w') as f:
			f.write(json.dumps(self.Map))
			self.addDisplayText('地圖保存成功-->map.txt')
		# else:
			# self.addDisplayText('地圖保存失敗')
	def button_LoadMap(self):
		try:
			with open('map.txt','r') as f:
				self.Map=json.loads(f.read())
				config.HEIGHT=len(self.Map)
				config.WIDTH=len(self.Map[0])
				self.addDisplayText('地圖加載成功')
				self.repaint()
		except Exception as e:
			print('失敗',e,type(e))
			if type(e)==FileNotFoundError:
				self.addDisplayText('地圖加載失敗:地圖檔案不存在')
			elif type(e)==json.decoder.JSONDecodeError:
				self.addDisplayText('地圖加載失敗:錯誤的地圖檔案')
	def button_Clear(self):
		sender=self.sender()
		print(self.button_clearSE,type(self.button_clearSE))
		if sender==self.button_clearSE:
			self.startPoint=None
			self.endPoint=None
			self.repaint()
			self.addDisplayText('清空起始點')
		elif sender==self.button_clearWall:
			for i in range(len(self.Map)):
				for j in range(len(self.Map[i])):
					self.Map[i][j]=0
			self.repaint()
			self.addDisplayText('清空所有墻壁')
	def paintEvent(self, event):
		qp = QPainter()
		qp.begin(self)
		self.drawBoard(event,qp)
		qp.end()
	def drawBoard(self, event, qp):
	    self.drawMap(qp)
	def drawMap(self,qp):#畫面繪制方法,每次地圖有所改動都將重繪
		time1=time.time()
		if self.search!=None:
			if self.special!=None:
				e=self.special[0]
				path=[e]
				while True:
					e=e.father
					if e!=None:
						path.append(e)
					else:
						break
			else:
				path=None
			pen=QPen(QColor(0,0,0),1,Qt.SolidLine)
			qp.setPen(pen)
			for i in range(len(self.Map)):
				for j in range(len(self.Map[i])):
					wordTag=False
					if i==self.search.start.x and j==self.search.start.y:
						qp.setBrush(QColor(255,255,0))
					elif i==self.search.end.x and j==self.search.end.y:
						qp.setBrush(QColor(100,200,50))
					else:
						if self.Map[i][j]==0:
							tagx=True
							if path:
								for k in path:
									if k.x==i and k.y==j:
										tagx=False
										qp.setBrush(QColor(0,100,255))
							if tagx:
								if self.special!=None:
									if i==self.special[0].x and j==self.special[0].y:
										qp.setBrush(QColor(0,255,0))
									else:
										tag=True
										for k in self.special[1]:
											if k.x==i and k.y==j:
												tag=False
												wordTag=True
												word=str(k.F)

												qp.setBrush(QColor(150,0,0))
												break
											else:
												qp.setBrush(QColor(220,220,220))
										if tag:
											for k in self.special[2]:
												if k.x==i and k.y==j:
													qp.setBrush(QColor(150,150,150))
													break
												else:
													qp.setBrush(QColor(220,220,220))
								else:
									qp.setBrush(QColor(220,220,220))
						elif self.Map[i][j]==1:
							qp.setBrush(QColor(0,0,0))
						else:
							qp.setBrush(QColor(255,0,0))
					qp.drawRect(50+j*config.blockLength,50+i*config.blockLength,config.blockLength,config.blockLength)
					if wordTag:
						qp.setFont(QFont('楷體',5,QFont.Light))
						qp.drawText(50+10+j*config.blockLength,50+10+i*config.blockLength,word)
						wordTag=False
		#time.sleep(20)
		else:
			for i in range(len(self.Map)):
				for j in range(len(self.Map[i])):
					if (j,i)==self.startPoint:
						qp.setBrush(QColor(255,255,0))
					elif (j,i)==self.endPoint:
						qp.setBrush(QColor(100,200,50))
					else:
						if self.Map[i][j]==0:
							qp.setBrush(QColor(220,220,220))
						elif self.Map[i][j]==1:
							qp.setBrush(QColor(0,0,0))
						else:
							qp.setBrush(QColor(255,0,0))

					qp.drawRect(50+j*config.blockLength,50+i*config.blockLength,config.blockLength,config.blockLength)
		time2=time.time()
	#time.sleep(20)
		# print('繪制時間:',time2-time1)
	def timerEvent(self,e):
		try:
			data=next(self.yi)
		except Exception as e:
			self.addDisplayText('搜索結束:')
			print('搜索結束!')
			if self.search.result==None:
				self.addDisplayText('未找到可行路徑')
				print('搜索結束!')
			else:
				self.addDisplayText('總計搜索節點數:%d'%self.search.count)
				self.addDisplayText('最終路徑長度:%d'%len(self.search.result))
			self.centerTimer.stop()
			self.search=None
			self.yi=None
			self.special=None
			point.clear()
			self.button_start.setEnabled(True)
			self.button_clearSE.setEnabled(True)
			self.button_clearWall.setEnabled(True)
			self.displayFlush=True
		else:
			self.special=data
			self.repaint()
if __name__ == '__main__':
	app = QApplication(sys.argv)
	ex = GameBoard()
	sys.exit(app.exec_())

注意:代碼運行可以設定動態遍歷的時候暫停時間(大概在145行的time.sleep(5)陳述句)

運行結果

輸出每次計算的每個點的F和父結點,直接看圖吧!

詳細串列

初始化地圖...
初始化UI...
<PyQt5.QtWidgets.QPushButton object at 0x0000017CC699AC18>
計算值: (2,3)[F=0,G=0,cost=10][father:((2, 2))]
F=40 G=10 H=30
計算值: (3,3)[F=0,G=0,cost=14][father:((2, 2))]
F=54 G=14 H=40
計算值: (3,2)[F=0,G=0,cost=10][father:((2, 2))]
F=60 G=10 H=50
計算值: (3,1)[F=0,G=0,cost=14][father:((2, 2))]
F=74 G=14 H=60
計算值: (2,1)[F=0,G=0,cost=10][father:((2, 2))]
F=60 G=10 H=50
計算值: (1,1)[F=0,G=0,cost=14][father:((2, 2))]
F=74 G=14 H=60
計算值: (1,2)[F=0,G=0,cost=10][father:((2, 2))]
F=60 G=10 H=50
計算值: (1,3)[F=0,G=0,cost=14][father:((2, 2))]
F=54 G=14 H=40
計算值: (3,3)[F=54,G=14,cost=10][father:((2, 3))]
F=60 G=20 H=40
計算值: (3,2)[F=60,G=10,cost=14][father:((2, 3))]
F=74 G=24 H=50
計算值: (1,2)[F=60,G=10,cost=14][father:((2, 3))]
F=74 G=24 H=50
計算值: (1,3)[F=54,G=14,cost=10][father:((2, 3))]
F=60 G=20 H=40
計算值: (4,4)[F=0,G=0,cost=14][father:((3, 3))]
F=68 G=28 H=40
計算值: (4,3)[F=0,G=0,cost=10][father:((3, 3))]
F=74 G=24 H=50
計算值: (4,2)[F=0,G=0,cost=14][father:((3, 3))]
F=88 G=28 H=60
計算值: (3,2)[F=60,G=10,cost=10][father:((3, 3))]
F=74 G=24 H=50
計算值: (1,2)[F=60,G=10,cost=10][father:((1, 3))]
F=74 G=24 H=50
計算值: (0,2)[F=0,G=0,cost=14][father:((1, 3))]
F=88 G=28 H=60
計算值: (0,3)[F=0,G=0,cost=10][father:((1, 3))]
F=74 G=24 H=50
計算值: (0,4)[F=0,G=0,cost=14][father:((1, 3))]
F=68 G=28 H=40
計算值: (4,3)[F=74,G=24,cost=14][father:((3, 2))]
F=74 G=24 H=50
計算值: (4,2)[F=88,G=28,cost=10][father:((3, 2))]
F=80 G=20 H=60
計算值: (4,1)[F=0,G=0,cost=14][father:((3, 2))]
F=94 G=24 H=70
計算值: (3,1)[F=74,G=14,cost=10][father:((3, 2))]
F=80 G=20 H=60
計算值: (2,1)[F=60,G=10,cost=14][father:((3, 2))]
F=74 G=24 H=50
計算值: (3,1)[F=74,G=14,cost=10][father:((2, 1))]
F=80 G=20 H=60
計算值: (3,0)[F=0,G=0,cost=14][father:((2, 1))]
F=94 G=24 H=70
計算值: (2,0)[F=0,G=0,cost=10][father:((2, 1))]
F=80 G=20 H=60
計算值: (1,0)[F=0,G=0,cost=14][father:((2, 1))]
F=94 G=24 H=70
計算值: (1,1)[F=74,G=14,cost=10][father:((2, 1))]
F=80 G=20 H=60
計算值: (1,2)[F=60,G=10,cost=14][father:((2, 1))]
F=74 G=24 H=50
計算值: (1,1)[F=74,G=14,cost=10][father:((1, 2))]
F=80 G=20 H=60
計算值: (0,1)[F=0,G=0,cost=14][father:((1, 2))]
F=94 G=24 H=70
計算值: (0,2)[F=88,G=28,cost=10][father:((1, 2))]
F=80 G=20 H=60
計算值: (0,3)[F=74,G=24,cost=14][father:((1, 2))]
F=74 G=24 H=50
計算值: (4,5)[F=0,G=0,cost=10][father:((4, 4))]
F=68 G=38 H=30
計算值: (5,5)[F=0,G=0,cost=14][father:((4, 4))]
F=82 G=42 H=40
計算值: (5,4)[F=0,G=0,cost=10][father:((4, 4))]
F=88 G=38 H=50
計算值: (5,3)[F=0,G=0,cost=14][father:((4, 4))]
F=102 G=42 H=60
計算值: (4,3)[F=74,G=24,cost=10][father:((4, 4))]
F=88 G=38 H=50
計算值: (3,5)[F=0,G=0,cost=14][father:((4, 4))]
F=62 G=42 H=20
計算值: (3,6)[F=0,G=0,cost=10][father:((3, 5))]
F=62 G=52 H=10
計算值: (4,6)[F=0,G=0,cost=14][father:((3, 5))]
F=76 G=56 H=20
計算值: (4,5)[F=68,G=38,cost=10][father:((3, 5))]
F=82 G=52 H=30
計算值: (2,5)[F=0,G=0,cost=10][father:((3, 5))]
F=62 G=52 H=10
計算值: (2,6)[F=0,G=0,cost=14][father:((3, 5))]
F=56 G=56 H=0
搜索結束!

可執行檔案

已經將程式打包成exe可執行檔案,點擊即可用,不需要py環境,

鏈接:https://pan.baidu.com/s/1TzFK0ODsf1JhfaMHn37uzQ 提取碼:3kyr

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/224281.html

標籤:python

上一篇:python爬取新筆趣閣小說

下一篇:初識c語言

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more