博客
关于我
2018焦作ICPC F. Honeycomb(bfs)
阅读量:748 次
发布时间:2019-03-22

本文共 799 字,大约阅读时间需要 2 分钟。

思路:比较简单的bfs,我们以每个六边形的中心作为这个六边形的一个整体。很容易看到有六个方向可以走。至于能不能走出去,只需要看六个方向的出口处A是不是空格,是空格的话,假设当前六边形中心为S,要走到的下一个六边形中心为T,容易知道从S走到T的方向和距离就是从S到A的两倍。

坑点

①如果走不到终点要输出-1,没注意看题目,以为保证能走到,wa了一发

②清空标记数组vis用两个for清空,不要用memset对所有点清空 不然会TLE

#include
using namespace std;const int N=(1e3+5)*6;int n,m;int dx[]={ -1,-1,-2,2,1,1};int dy[]={ -3,3,0,0,-3,3};char mp[N][N];bool vis[N][N];int sx,sy;struct node{ int x,y,st;};void bfs(){ for(int i=0;i
que; que.push({ sx,sy,1}); vis[sx][sy]=1; while(!que.empty()){ node now=que.front(); que.pop(); int x=now.x,y=now.y,st=now.st; if(mp[x][y]=='T') { cout<
<
=0 && fx
=0 && fy
>T; while(T--){ cin>>n>>m; n=4*n+3; m=6*m+3; getchar(); for(int i=0;i

转载地址:http://auhwk.baihongyu.com/

你可能感兴趣的文章
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>