训练之搜索约会2
2016-07-21 15:10
225 查看
Dating with girls(2)Crawling in process...
Crawling failed
Time Limit:5000MS
Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
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.
![](http://7xjob4.com1.z0.glb.clouddn.com/dd753a737c8418c3a103c1d206c17fec)
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.
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
1
6 6 2
...Y..
...#..
.#....
...#..
...#..
..#G#.
Sample Output
7
一道搜索题,增加了当时间是k的倍数是可以穿过墙,多一重判断是否可以穿过墙就好了。
Crawling failed
Time Limit:5000MS
Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
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.
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.
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
1
6 6 2
...Y..
...#..
.#....
...#..
...#..
..#G#.
Sample Output
7
一道搜索题,增加了当时间是k的倍数是可以穿过墙,多一重判断是否可以穿过墙就好了。
#include<stdio.h> #include<queue> using namespace std; char map[110][110]; int dir[4][2]={-1,0,0,-1,1,0,0,1}; int ans[110][110][15]; int n,m,k,yx,yy,gx,gy; struct node { int x,y,t; }; int BFS() { queue<node> qu; node p1; p1.x=yx; p1.y=yy; p1.t=0; qu.push(p1); while(qu.size()) { p1=qu.front(); qu.pop(); if(map[p1.x][p1.y]=='G') return p1.t; for(int i=0;i<4;i++) { node p2; int px=p1.x+dir[i][0]; int py=p1.y+dir[i][1]; if(px<0||px>=n||py<0||py>=m) continue; p2.x=px; p2.y=py; p2.t=p1.t+1; int tk=p2.t%k; if(map[px][py]=='G') return p2.t; if(map[px][py]!='#'&&ans[px][py][tk]>p2.t) { ans[px][py][tk]=p2.t; qu.push(p2); } else if(tk==0&&ans[px][py][tk]>p2.t) { ans[px][py][tk]=p2.t; qu.push(p2); } } } return -1; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); for(int i=0;i<n;i++) scanf("%s",map[i]); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(map[i][j]=='Y') {yx=i;yy=j;} if(map[i][j]=='G') {gx=i;gy=j;} } } for(int i=0;i<n;i++) for(int j=0;j<m;j++) for(int z=0;z<=k;z++) ans[i][j][z]=999999; ans[yx][yy][0]=0; int anst; anst=BFS(); if(anst==-1) printf("Please give me another chance!\n"); else printf("%d\n",anst); } return 0; }
相关文章推荐
- 搜狗百度360市值齐跌:搜索引擎们陷入集体焦虑?
- 本人即将筹备败家日志,敬请期待!
- IE:使用搜索助手
- C++深度优先搜索的实现方法
- 基于文本的搜索
- php实现搜索一维数组元素并删除二维数组对应元素的方法
- 使用Sphinx对索引进行搜索
- asp 多关键词搜索的简单实现方法
- C#使用foreach语句搜索数组元素的方法
- WordPress中用于获取搜索表单的PHP函数使用解析
- JavaScript中数组的排序、乱序和搜索实现代码
- jquery ztree实现树的搜索功能
- 【经典源码收藏】jQuery实用代码片段(筛选,搜索,样式,清除默认值,多选等)
- C#编程实现Excel文档中搜索文本内容的方法及思路
- sqlserver中在指定数据库的所有表的所有列中搜索给定的值
- 可以用来搜索当前页面内容的js代码
- 全文搜索和替换
- javascript搜索自动提示功能的实现第1/3页
- iOS应用中UISearchDisplayController搜索效果的用法
- mysql 模糊搜索的方法介绍