nyoj 284 坦克大戰 簡單搜尋

2022-07-28 22:45:24 字數 868 閱讀 7891

題意:在乙個給定圖中,鐵牆,河流不可走,磚牆走的話,多花費時間1,問從起點到終點至少需要多少時間。

思路:簡單廣搜~

**如下:

#include "stdio.h" //nyoj 284 坦克大戰 簡單搜尋

#include "string.h"

#include "queue"

using namespace std;

#define n 305

#define inf 0x3fffffff

int n,m;

char map[n][n];

int time[n][n];

int dir[4][2] = ,,,};

struct node

start,end;

bool budge(node a)

int bfs()

{ int i;

queueq;

q.push(start);

node cur,next;

while(!q.empty())

{cur = q.front();

q.pop();

for(i=0; i<4; ++i)

{next.x = cur.x+dir[i][0];

next.y = cur.y+dir[i][1];

if(budge(next)) continue; //該點越界或不可走,continue;

next.time = cur.time+1;

if(map[next.x][next.y]=='b')

next.time++;

if(next.time

坦克大戰(nyoj284)

題目大體意思就是,求從地圖上的y走到t的最小步數,其中s和r不能走,b要走兩步,e要走一步。測試輸入 3 4 ybeb eere sste 0 0測試輸出 8 這個題要用優先佇列,不用的話沒有辦法保證所求的步數是最小的。我也查了一些關於優先佇列的資料,做以下整理 在優先佇列中,優先順序高的元素先出佇...

NYOJ284坦克大戰

bfs求最短路,這個題走到 b 點是要花費2個時間,e 是1個時間,所以要用乙個優先佇列,優先順序就是花費小的先出隊,其餘的就是模板了。include include include using namespace std define inf 0x3f3f3f3f int stx,sty int ...

nyoj284 坦克大戰 搜尋 bfs

樣例輸入 3 4ybeb eere sste 0 0樣例輸出 8 題意 從y字母的位置到t字母的位置最少trun了幾次 遇到r,s不能走,遇到b的話要turn 2次。坑點在必須用優先佇列,hiphop man 為什麼?真的不知道 不喜歡你的style kkk include include incl...