前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Wannafly挑战赛17 A走格子

Wannafly挑战赛17 A走格子

作者头像
用户2965768
发布2018-08-30 16:31:17
3110
发布2018-08-30 16:31:17
举报
文章被收录于专栏:wymwym

#include <bits/stdc++.h> using namespace std; struct node{ int x,y; int step; }; int dir[][2]={1,0, 0,1, -1,0, 0,-1}; int n,m; int ansx,ansy; int book[1001][1001]; void bfs(int x,int y,int step) { int i=0;   queue<node> p;   node q;   q.x=x; q.y=y; q.step=step;    p.push(q);     while(!p.empty())  { node z=p.front(); if(z.step==m)  {ansx=z.x; ansy=z.y; return;  } p.pop(); int tx=z.x+dir[i][0]; int ty=z.y+dir[i][1]; while(!(tx<=n&&tx>0&&ty>0&&ty<=n&&!book[tx][ty]))       {        i++; i=i%4; tx=z.x+dir[i][0]; ty=z.y+dir[i][1];   }   book[tx][ty]=1;     node tp; tp.x=tx; tp.y=ty;  tp.step=z.step+1;     p.push(tp);       } } int main() { while(~scanf("%d %d",&n,&m)) { memset(book,0,sizeof(book));         book[1][1]=1; bfs(1,1,0); printf("%d %d\n",ansx,ansy); } return 0; }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年06月08日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档