CCF201604 4 遊戲(兩種解法分析)

2021-10-03 08:52:34 字數 2183 閱讀 2872

本題的標記陣列顯然不能使用二維,為了保證安全到達目標結點,角色可以在不同的時間到達同一地點(因為角色必須保持移動所以只能是迂迴而不是滯留),所以考慮為標記陣列增加乙個時間維度,由於題目所給資料危險時間段的範圍為0到100,範圍較小,所以無需考慮狀態壓縮,接下來的操作和基礎廣搜相同,但這樣提交之後只能得到70分,這也是這道題目的乙個大坑,給出資料範圍去誤導做題者申請標記陣列的大小。

考慮極端情況,在0-100時間單位內除起始結點外其他所有結點均處於不可訪問的狀態,那麼前100時間內角色是停留在原地的(假設可以滯留),又因為從起點到終點的最長時間(不回退的情況下)為200,故我們標記陣列的第三維的大小至少為300。

#include

#include

#include

using

namespace std;

typedef

long

long ll;

bool vis[

110]

[110][

350]

;int dis[

2]=,

,,};

int n,m,t,r,c,a,b;

struct ss(

int xx,

int yy,ll tt):x

(xx),y

(yy),t

(tt)};

bool

move

(int x,

int y,

int t)

intmain()

queue q;

q.push(s

(1,1

,0))

; vis[1]

[1][

0]=1

;while

(!q.

empty()

)for

(int i=

0;i<

4;i++

)}

q.pop();

}}return0;

}

此解法可以解決爆記憶體的情況,比如時間範圍特別大時,這時就考慮使用優先佇列進行優化(其實是相當於邊權均為一時的dijkstra演算法),優先選擇當前步數最小的點出隊進行擴充套件。在本題中,由於角色需要不停地移動,所以遇到危險時,時間要分兩種情況:end+1/end+2

(1)end+1:(end-now)%2=0

(2)end+2:(end-now)%2=1

其中 end為危險的最後乙個時間單位,now是移動前的時間

然**隊,其餘操作與基礎廣搜相同,不再贅述。

#include

#include

#include

using

namespace std;

bool vis[

110]

[110];

int begin[

110]

[110];

int end[

110]

[110];

int dis[

2]=,

,,};

int n,m,t,r,c,a,b;

struct ss(

int xx,

int yy,

int tt):x

(xx),y

(yy),t

(tt)

friend

bool

operator

<

(const s &s1,

const s &s2)};

bool

move

(int x,

int y)

intmain()

priority_queue q;

q.push(s

(1,1

,0))

; vis[1]

[1]=

1;while

(!q.

empty()

)for

(int i=

0;i<

4;i++

) q.

push(s

(dx,dy,dt));

vis[dx]

[dy]=1

;}}

q.pop();

}}return0;

}

PL SQL Developer過期的兩種解決方法

方法一 1.首先,登陸pl sql developer,pl sql developer要到期了 2.輸入指令 regedit 程式設計客棧開啟登錄檔,如圖所示 3.然後,在登錄檔裡按hkey current user software allround automations 這個路徑找到 all...

springmvc靜態資源過濾問題,兩種解決方法

1.tomcat的專案路徑設定為 2.springmvc.xml設定靜態資源不過濾 設定靜態資源不過濾 resources css location resources css resources js location resources js resources images location ...

Android兩種常見錯誤(ANR和FC)解決辦法

anr activity not respone 無響應 先介紹下main執行緒 也稱為ui執行緒 主線程 功能 1.建立ui控制項 2.更新ui控制項狀態 3.事件處理 限制 main執行緒不建議有超過5秒的事件 出現條件 當使用者輸入事件5s內沒有得到響應,將彈出anr對話方塊 廣播接收者的on...