首页 > 代码库 > hdu 2579
hdu 2579
V - Dating with girls(2)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uAppoint description:
Description
If you have solved the problem Dating with girls(1).I think you can solve this problem too.This problem is also about dating with girls. Now you are in a maze and the girl you want to date with is also in the maze.If you can find the girl, then you can date with the girl.Else the girl will date with other boys. What a pity!
The Maze is very strange. There are many stones in the maze. The stone will disappear at time t if t is a multiple of k(2<= k <= 10), on the other time , stones will be still there.
There are only ‘.’ or ‘#’, ’Y’, ’G’ on the map of the maze. ’.’ indicates the blank which you can move on, ‘#’ indicates stones. ’Y’ indicates the your location. ‘G’ indicates the girl‘s location . There is only one ‘Y’ and one ‘G’. Every seconds you can move left, right, up or down.
The Maze is very strange. There are many stones in the maze. The stone will disappear at time t if t is a multiple of k(2<= k <= 10), on the other time , stones will be still there.
There are only ‘.’ or ‘#’, ’Y’, ’G’ on the map of the maze. ’.’ indicates the blank which you can move on, ‘#’ indicates stones. ’Y’ indicates the your location. ‘G’ indicates the girl‘s location . There is only one ‘Y’ and one ‘G’. Every seconds you can move left, right, up or down.
Input
The first line contain an integer T. Then T cases followed. Each case begins with three integers r and c (1 <= r , c <= 100), and k(2 <=k <= 10).
The next r line is the map’s description.
The next r line is the map’s description.
Output
For each cases, if you can find the girl, output the least time in seconds, else output "Please give me another chance!".
Sample Input
16 6 2...Y.....#...#.......#.....#....#G#.
Sample Output
7
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cstdlib>#include<cmath>#include<algorithm>#include<queue>#include<vector>#include<set>using namespace std;int n,m,k;int x_s,y_s;int x_e,y_e;char map[111][111];int step[10][111][111];int dir[4][2]={0,1, 1,0, 0,-1, -1,0};struct node{ int f,x,y;};int BFS(){ queue<node>q; node now,next; int i; memset(step,-1,sizeof(step)); now.f=0; now.x=x_s; now.y=y_s; q.push(now); step[now.f][now.x][now.y]=0; while(!q.empty()) { now=q.front(); q.pop(); if(now.x==x_e && now.y==y_e) return step[now.f][now.x][now.y]; for(i=0;i<4;i++) { next.x=now.x+dir[i][0]; next.y=now.y+dir[i][1]; next.f=(now.f+1)%k; if(next.x<0 || next.x>=n || next.y<0 || next.y>=m) continue; if(map[next.x][next.y]==‘#‘ && next.f) continue; if(step[next.f][next.x][next.y]!=-1) continue; step[next.f][next.x][next.y]=step[now.f][now.x][now.y]+1; q.push(next); } } return -1;}int main(){ int T; int i,l; int ans; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&k); for(i=0;i<n;i++) { scanf("%s",map[i]); for(l=0;map[i][l];l++) { if(map[i][l]==‘Y‘) {x_s=i;y_s=l;map[i][l]=‘.‘;} if(map[i][l]==‘G‘) {x_e=i;y_e=l;map[i][l]=‘.‘;} } } ans=BFS(); if(ans==-1) printf("Please give me another chance!\n"); else printf("%d\n",ans); } return 0;}
有点dp的味道,,写了一个 调了一晚上没调出来,,真是弱爆了,,上标程。。。。
hdu 2579
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。