HDU 2579 Dating with girls(2)
来源:互联网 发布:淘宝提醒买家付款 编辑:程序博客网 时间:2024/05/01 18:32
bfs。。。
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>#include<queue>#include<cmath>using namespace std;const int maxN=110;char map[maxN][maxN];int n,m,dx[]={1,-1,0,0},dy[]={0,0,1,-1},k;bool vis[maxN][maxN][20];struct Point{ int x,y,time; Point(int _x,int _y,int _time):x(_x),y(_y),time(_time){}};void bfs(int x,int y){ queue<Point> q; q.push(Point(x,y,0)); memset(vis,false,sizeof(vis)); vis[x][y][0]=true; while(!q.empty()){ Point p=q.front();q.pop(); if(map[p.x][p.y]=='G') { cout<<p.time<<endl; return; } for(int i=0;i<4;i++){ int nx=p.x+dx[i],ny=p.y+dy[i]; if(nx<0||nx>=n||ny<0||ny>=m||vis[nx][ny][(p.time+1)%k]) continue; vis[nx][ny][(p.time+1)%k]=true; if(map[nx][ny]=='#'){ if((p.time+1)%k==0) q.push(Point(nx,ny,p.time+1)); } else q.push(Point(nx,ny,p.time+1)); } } cout<<"Please give me another chance!"<<endl;}int main(){#ifndef ONLINE_JUDGE freopen("a.in","r",stdin); freopen("a.out","w",stdout);#endif int t; cin>>t; while(t--){ cin>>n>>m>>k; int sx,sy; for(int i=0;i<n;i++){ scanf("%s",map[i]); for(int j=0;j<m;j++) if(map[i][j]=='Y') sx=i,sy=j; } bfs(sx,sy); } return 0;}
- HDU 2579 Dating with girls(2) BFS
- HDU 2579 Dating with girls(2)
- hdu 2579 Dating with girls(2)
- HDU 2579 Dating with girls(2)
- hdu(2579) Dating with girls(2)
- HDU 2579 Dating with girls(2)
- HDU 2579 Dating with girls(2)(BFS)
- HDU 2579 - Dating with girls(2)
- HDU 2579 Dating with girls(2)
- hdu 2579 Dating with girls(2)
- HDU 2579 Dating with girls(2) (BFS)
- HDU 2579 Dating with girls(2)
- hdu 2579 Dating with girls(2)【bfs】
- hdu 2579 Dating with girls(2)
- HDU 2579/BFS/ Dating with girls(2)
- HDU 2579 Dating with girls(2)
- Dating with girls(2) HDU
- hdu 2579 Dating with girls(2)(BFS)
- 命令行运行android模拟器
- POJ 2250解题报告
- 加勒比的伤感爱情日志分享:如果你知道我也爱你
- Android 秒表
- Java编程中“为了性能”需做的26件事
- HDU 2579 Dating with girls(2)
- 指针数组和数组指针的使用
- 小结构与小算法:利用树结构求集合的幂集
- 花花公子推荐伤感qq日志:乖不哭,我拜你
- 【作废】Inventor 二次开发学习指南入门到精通(含Inventor最新二次开发教程下载)
- 苏沫沫的原创伤感日志发布:我爱你比爱自己更过分
- SQLite学习
- 访问JSP文件或者Servlet文件时提示下载的解决方法
- OpenCV 下的图像任意角度的旋转