HDU ACM 1728 逃離迷宮 (廣搜BFS)

http://acm.hdu.edu.cn/showproblem.php?pid=1728

題意:給出一張圖,轉彎數k,起點(x1,y1),(x2,y2)判斷能不能最多只轉k個彎時從起點走到終點

   輸入時注意起點與終點是先y后x的

思路:用point[4][2]表示方向向量,每次遍歷遍歷一行或者一列,遍歷時要注意遇到遍歷過的點要跳過去,繼續遍歷他后面的點而不是直接結束.

?  由于每次遍歷一行所以并不需要記錄初始方向.

  記錄轉彎次數則在每一取隊頭時,把轉彎數+1.

還是不懂得化去看看KIDx大牛的http://972169909-qq-com.iteye.com/blog/1244218

View Code
  1 #include<iostream>
  2 #include <queue>
  3 using namespace std;
  4 const int MAX = 100 + 10;
  5 const int INF = 0x3fffffff;
  6 char map[MAX][MAX];
  7 int used[MAX][MAX];
  8 int point[4][2]={{0,1},{1,0},{0,-1},{-1,0}};//
  9 struct Node
 10 {
 11     int x;
 12     int y;
 13     int turn;
 14 };
 15 int x,y;
 16 int BFS(Node a,Node b)
 17 {
 18     memset(used,0,sizeof(used));
 19     queue <Node> q;
 20     a.turn = -1;
 21     q.push(a);
 22     used[a.x][a.y] = 1;
 23     while(!q.empty())
 24     {
 25         Node mid;
 26         mid = q.front();
 27 
 28         q.pop();
 29         if(mid.x == b.x && mid.y == b.y)
 30         {
 31             b.turn = mid.turn;
 32         }
 33         int i;
 34         mid.turn++;
 35         for(i=0;i<4;i++)
 36         {
 37 
 38             a.x = mid.x + point[i][0];
 39             a.y = mid.y + point[i][1];
 40             a.turn = mid.turn;
 41 
 42             while(1)
 43             {
 44                 if(map[a.x][a.y]!='*' && a.x>0 && a.y>0 && a.x<=x && a.y<=y)
 45                 {
 46                     if( used[a.x][a.y] == 1 )
 47                     {
 48                         a.x = a.x + point[i][0];
 49                         a.y = a.y + point[i][1];
 50 
 51                     }
 52                     else
 53                     {
 54 
 55                         q.push(a);
 56                         used[a.x][a.y] = 1;
 57                         a.x = a.x + point[i][0];
 58                         a.y = a.y + point[i][1];
 59 
 60                     }
 61                 }
 62                 else
 63                 {
 64                     break;
 65                 }
 66             }
 67         }
 68     }
 69     return b.turn;
 70 }
 71 
 72 int main()
 73 {
 74     int T;
 75     cin>>T;
 76     while(T--)
 77     {
 78         memset(map,0,sizeof(map));
 79         cin>>x>>y;
 80         int i,j;
 81         for(i=1;i<=x;i++)
 82         {
 83             for(j=1;j<=y;j++)
 84             {
 85                 cin>>map[i][j];
 86             }
 87         }
 88         int k;
 89         Node a,b;
 90         cin>>k>>a.y>>a.x>>b.y>>b.x;
 91         b.turn = INF;
 92         if( BFS(a,b) <= k)
 93         {
 94             cout<<"yes"<<endl;
 95         }
 96         else
 97         {
 98             cout<<"no"<<endl;
 99         }
100     }
101     return 0;
102 }

?

?

?

轉載于:https://www.cnblogs.com/zxotl/archive/2012/08/27/2659119.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274638.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274638.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274638.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Element使用的async-validator表單校驗庫源碼超詳細解析

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

從零手寫 Vue 之響應式系統

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外…

WPF 分頁控件應用

效果圖&#xff1a; 前臺代碼&#xff1a; <UserControl x:Class"Layout.UI.Comm.Pager"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc"http:/…

李寧品牌重塑_邁伊多品牌重塑的幕后

李寧品牌重塑This post was originally published on the Maido blog.這篇文章最初發表在 Maido博客上 。 You might notice that we’ve had a little facelift at Maido. Or you might not — and that’s totally fine. What we launched at the end of last year was not r…

搭建前端監控,如何采集異常數據?

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

產品經理如何提高創造力_如何提高產品設計師的創造力

產品經理如何提高創造力When David Kelley, Bill Moggridge, and Mike Nuttall founded IDEO, a consulting firm that would become one of the most innovative companies of the late 90s, they brought a new perspective in product development.當大衛凱利(David Kelley)…

Github上8個很棒的Vue項目

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

域名解析文件hosts文件是什么?如何修改hosts文件?

如何修改hosts文件&#xff1f; hosts文件的位置&#xff1a;xp,2000等系統在 C:\windows\system32\drivers\etc 文件夾中找到Hosts文件并用記事本打開(Windows 9x/Me系統在C:\Windows文件夾中找)按照 ip地址 域名 的格式添加單獨的一行記錄。例如72.14.219.190 www.hbcms.net…

python 投資組合_成功投資組合的提示

python 投資組合Lately, I’ve had some free time during my job transition and have been reviewing a few of my friends’ design portfolios. Gradually, I found some common themes around the feedback I’ve given. And it occurred to me that others might find so…

Github上8個很棒的React項目

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

騰訊的筆試題一道

搜羅了一些騰訊的筆試題目 題目是這樣的&#xff1a;在如下8*6的矩陣中&#xff0c;請計算從A移動到B一共有多少種走法&#xff1f;要求每次只能向上揮著向右移動一格&#xff0c;并且不能經過P&#xff1b; B P …

屏幕廣播系統_如何設計系統,而不是屏幕

屏幕廣播系統重點 (Top highlight)Over the past several decades, rapid advances in technology have dramatically enhanced the digital customer experience and their expectations. In the face of these heightened customer expectations, the role of the Interactio…

Umi 4 發布啦

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

Win32匯編--加載菜單資源

基本上的窗口都會有一個菜單,現在就來看看Win32匯編中是如何加載菜單的: 1>在工程中添加新的菜單資源 2>雙擊新添加的菜單資源進行編輯 3>菜單欄:Make->Compile RC來編譯資源文件 4>導出資源中的ID號并寫到數據段的.const中 5>下面是完整的源代碼供參考:(工程…

Futura:從納粹主義到月球-甚至更遠

Reading the title of this article, the first thing that will come to mind for some is the funny expression of Buzz Lightyear — the Disney character — when he stretches his arms outwards and utters the famous phrase “To infinity and beyond!” before jump…

如何碎片化時間高效學習前端~

前端技術日新月異&#xff0c;發展迅速&#xff0c;作為一個與時俱進的前端工程師&#xff0c;需要不斷的學習。這里強烈推薦幾個前端開發工程師必備的優質公眾號&#xff0c;希望對你有所幫助。大家可以像我一樣&#xff0c;利用碎片時間閱讀這些公眾號的文章。前端從進階到入…

爬取淘寶定價需要多久時間_如何對設計工作進行定價—停止收??取時間并專注于價值

爬取淘寶定價需要多久時間Pricing creative work is a new concept for most freelancers who are starting their business. We are used to being paid for our time, either by an hourly wage or an annual salary. It makes it simple to quantify how much value we thin…

OEA 框架中集成的 RDLC 報表介紹

之前 OEA 一直用著一個 Delphi 開發的報表&#xff0c;所以兩年來我一直就想在 OEA 中構建一個純 .NET 的報表模塊&#xff0c;但是一想到要開發復雜的報表引擎和設計器就覺得麻煩。所以這事一直拖著。最近開始研究一些成熟的報表引擎&#xff0c;經過對比&#xff0c;還是發現…

昆蟲繁殖_“專為昆蟲而生” –好奇!

昆蟲繁殖重點 (Top highlight)The industry is changing towards a more agile approach and jacks of one trade can go extinct sooner than we think.該 行業正在發生變化 朝著更加靈活的方法和一個貿易的插Kong可以去滅絕快于我們的想法。 I’ve read a quote in a book r…

ECMAScript 2022 正式發布,有哪些新特性?

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…