人工智慧導論 上機 A 解決八數碼問題

2021-10-10 23:01:19 字數 2571 閱讀 2569

a*演算法的精髓:

f (n

)=g(

n)+h

(n

)f(n)=g(n)+h(n)

f(n)=g

(n)+

h(n)

h (n

)h(n)

h(n)

是當前狀態n

nn到目標狀態的曼哈頓距離和。利用堆優化bfs

bfsbf

s即可。還可以在bfs

bfsbf

s時記錄前驅,然後倒著找到路線方案。

/*

* @author: codancer

* @createtime: 2020-11-28, 17:31:10

*/#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace std;

typedef

long

long ll;

typedef

unsigned

long

long ull;

const ll mod =

1e9+7;

#define pb push_back

#define fi first

#define se second

#define sz(x) ((int)(x).size())

#define rep(i,a,b) for(int i=(a);i<=(b);i++)

#define fep(i,a,b) for(int i=(a);i>=(b);i--)

#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"

typedef vector<

int> vi;

typedef vector vii;

typedef pair<

int,

int> pii;

mt19937_64 rng

(chrono::steady_clock::

now().

time_since_epoch()

.count()

);ll rand

(ll b)

struct status

;bool

operator

<

(status a,status b)

mapint>

>

,int

> vis;

priority_queue q;

inth

(vectorint>

> bd)

}return ans;

}vectorint>

> target=,,

};int dir[4]

[2]=

,,,}

;mapint>>

,vectorint>>

> pre;

inta_star

(vectorint>

> board));

while

(!q.

empty()

) vectorint>

> q_board=now.bd;

//當前局勢

int zx,zy;

//0所在的位置

for(

int i=

0;i<

3;i++)}

}for

(int i=

0;i<

4;i++))

;}}}

return-1

;}vectorint>

> board;

intmain()

board.

pb(row);}

cout<<

"最少步數"

a_star

(board)

int i=

0;i<

3;i++

) cout<} cout

>

> order;

mapint>>

,int

> cnt;

while

(target!=board)

reverse

(order.

begin()

,order.

end())

;for

(auto v:order)

cout<} cout<}return0;

}

人工智慧導論

人工智慧 能力 是智慧型機器所執行的通常與人類智慧型 有關的智慧型行為,如判斷 推理 證明 識別 感知 理解 通訊 設計 思考 規劃 學習和問題求解等 思維活動。凡是固定了演算法的,基本上都不算ai 弱人工智慧 在某個方面的智慧型 應用效果很強 強人工智慧 綜合的多方面的人工智慧 現實應用效果差 機...

人工智慧導論

1 人工智慧 讓機器像人一樣具有一些能力,擴充套件人的智慧型。2 機器學 不顯式程式設計地賦予計算機能力的研究領域。3 aiops artificial intelligence for it operations,智慧型化運維,將人工智慧應用於運維領域,基於已有的運維資料 日誌 監控資訊 應用資訊...

人工智慧導論(2) 啟發式演算法(八數碼問題)

用a 演算法來解決八數碼問題。include include include using namespace std int open cnt 0 int open node cnt open表節點個數 int close cnt 0 int noresoult 0 struct nodestart...