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.mzph.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余篇源码文章。历史面试系列。…

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余篇源码文章。历史面试系列。…

屏幕广播系统_如何设计系统,而不是屏幕

屏幕广播系统重点 (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余篇源码文章。历史面试系列。…

字母框如何影响UI内容的理解

What is your earliest memory of reading? Mine’s reading comics. I preferred films over books, I still do, but I seemed to have a fascination for comics. The experience of reading a comic, to me, was somewhere between watching a film and reading a novel, …

Vue2.7 本周发布?支持组合式 API、setup、css v-bind

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…