HDU1010 奇偶剪枝 dfs)

2021-09-10 18:06:38 字數 1388 閱讀 8851

the doggie found a bone in an ancient maze, which fascinated him a lot. however, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. he realized that the bone was a trap, and he tried desperately to get out of this maze.

『x』: a block of wall, which the doggie cannot enter;

『s』: the start point of the doggie;

『d』: the door; or

『.』: an empty block.

the input is terminated with three 0』s. this test case is not to be processed.

output

for each test case, print in one line 「yes」 if the doggie can survive, or 「no」 otherwise.

sample input

4 4 5

s.x.

…x.…xd

…3 4 5

s.x.

…x.…d

0 0 0

sample output

noyes

題意是說要要在特定的t時間到達出口,而不是在t時間內到達出口,所以不適合用bfs,用dfs最好,記得每個路線走過的格仔要標記,路線走完後要恢復。

該題直接用bfs會超時,得結合奇偶剪枝。詳見**

ac**

#include #include #include #include #include #include #include #includeusing namespace std;

int ji[10][10],n,m,t,v,n;

char p[10][10];

int a, s, d,sum=0;

int s1[4] = , s2[4] = ;

void dfs(int x, int y, int time)

if (time > t)return;

int ***, yyy;

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

}int main()

if (p[i][j] == 'd')

}ji[a][d] = 1;

dfs(a,d,0);

if (!sum)cout << "no" << endl;

}}

HDU1010 奇偶剪枝 DFS

第一次做剪枝的題目,剪枝,說實話研究的時間不短。好像沒什麼實質性的進展,遇到題目。絕對有會無從下手的感覺,剪枝越來越神奇了。hdu1010一道剪枝的經典題目,自己當初想用bfs過。提交了10幾遍wa,後來查了是剪枝最終死心了 ps 第一次寫剪枝題目,用了乙個模擬地圖來做奇偶性的判定條件進行剪枝,大牛...

dfs奇偶剪枝 HDU 1010

題意 問小狗是否能在第t秒 走t步 從s點到達d點 思路 很明顯的一道dfs題目,但是我們這裡需要採用剪枝減少不必要的路,另外這裡的地圖是字元,我們輸入需要注意吸收換行符 另外如果找到了答案,我們用全域性變數把它標記,只要它找到了答案,後面的操作不用進行 include include includ...

hdu1010迷宮搜尋 奇偶剪枝

n m t 4 4 5 s為起點,能否恰好t步走到d,x是牆,s.x.直接搜尋超時,根據曼哈頓距離可以排除一些情況,x.易知起點到終點的最短距離為兩點曼哈頓距離,xd 則若計算的距離大於最短距離,距離之差相當於 走完最短距離又出去走了一段又回來,一定是偶數 no3 4 5 s.x.x.d 0 0 0...