From 31fd7e7d3f2e95736ad30d5bd9e01d61d0cc1775 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 4 Oct 2016 18:35:29 +0800 Subject: [PATCH] Create 52307_keyboarderqq.cpp From http://blog.csdn.net/keyboarderqq/article/details/52730750 --- BNUOJ/52307_keyboarderqq.cpp | 109 +++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 BNUOJ/52307_keyboarderqq.cpp diff --git a/BNUOJ/52307_keyboarderqq.cpp b/BNUOJ/52307_keyboarderqq.cpp new file mode 100644 index 0000000..1cd08d9 --- /dev/null +++ b/BNUOJ/52307_keyboarderqq.cpp @@ -0,0 +1,109 @@ +#include +using namespace std; +typedef long long LL; + +const int N=2e2+10; + +struct asd{ + int x,y; +}; +int dx[4]={0,0,-1,1}; +int dy[4]={1,-1,0,0}; +char s[N][N]; +int step[N][N]; +int n,m; +int sx,sy; +queueq; + +void init() +{ + while(!q.empty()) + q.pop(); + memset(step,-1,sizeof(step)); +} + +bool Judge(int x,int y) +{ + if(x<0||y<0||x>=n||y>=m) + return 0; + if(s[x][y]=='#') + return 0; + return 1; +} + +void bfs() +{ + init(); + asd now,next; + now.x=sx; + now.y=sy; + step[now.x][now.y]=0; + q.push(now); + while(!q.empty()) + { + now=q.front(); + q.pop(); +// printf("%d %d\n",now.x,now.y); + for(int i=0;i<4;i++) + { + int x=now.x+dx[i]; + int y=now.y+dy[i]; + if(Judge(x,y)) + { + if(step[x][y]==-1) + { + step[x][y]=step[now.x][now.y]+1; + next.x=x; + next.y=y; + q.push(next); + } + } + } + } + int temp1; + int temp2=0x3f3f3f3f; + for(int i=0;i