HDU2579--Dating with girls(2)--(DFS, 判重)
Dating with girls(2)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1418 Accepted Submission(s): 393
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.
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.
6 6 2
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int n,m,k,sx,sy,ex,ey;
struct haha
{
int x, y, step;
}q,temp;
char map[][];
int dir[][]={,,,-,,,-,};
int vis[][][];
void BFS()
{
int i;
q.x=sx;
q.y=sy;
q.step=;
queue<struct haha>que;
memset(vis,,sizeof(vis));
vis[sx][sy][]=;
que.push(q);
while(!que.empty())
{
temp=que.front();
que.pop();
if(temp.x==ex&&temp.y==ey)
{
printf("%d\n",temp.step);
return ;
}
for(i=;i<;i++)
{
int xx,yy;
xx=temp.x+dir[i][];
yy=temp.y+dir[i][];
if(xx>=&&xx<n&&yy>=&&yy<m&&(map[xx][yy]!='#'||(temp.step+)%k==)&&!vis[xx][yy][(temp.step+)%k])
{
q.step=temp.step+;
q.x=xx;
q.y=yy;
vis[xx][yy][(temp.step+)%k]=;
que.push(q);
}
}
}
printf("Please give me another chance!\n");
}
int main()
{
int i,j,cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d %d %d",&n,&m,&k);
for(i=;i<n;i++)
{
scanf("%s",map[i]);
for(j=;j<m;j++)
{
if(map[i][j]=='Y') {sx=i;sy=j;}
else if(map[i][j]=='G') {ex=i;ey=j;}
}
}
BFS();
}
return ;
}
HDU2579--Dating with girls(2)--(DFS, 判重)的更多相关文章
- UVa 10400 - Game Show Math 游戏中的数学 dfs+判重
题意:给出一些数字和一个目标数字,要求你在数字间添加+-*/,让表达式能达到目标数字,运算符号的优先级都是一样的. 由于数据量很大,本来想用map<string>判重的,结果还是超时了,然 ...
- POJ 2458 DFS+判重
题意: 思路: 搜+判重 嗯搞定 (听说有好多人用7个for写得-.) //By SiriusRen #include <bitset> #include <cstdio>0 ...
- 【DFS+小操作判重】【HDU2610+HDU2611】Sequence
题意 2610 按照长度优先 位置次之 输出所有不递减序列 2611 按照长度优先 大小次之 输出所有不递减序列 题解不写了 来源于http://www.cnblogs.com/wally/archi ...
- poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)
Sum It Up Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Sub ...
- hdu 2610 2611 dfs的判重技巧
对于全排列枚举的数列的判重技巧 1:如果查找的是第一个元素 那么 从0开始到当前的位置看有没有出现过这个元素 出现过就pass 2: 如果查找的不是第一个元素 那么 从查找的子序列当前位置的前一个元素 ...
- 八数码问题+路径寻找问题+bfs(隐式图的判重操作)
Δ路径寻找问题可以归结为隐式图的遍历,它的任务是找到一条凑够初始状态到终止问题的最优路径, 而不是像回溯法那样找到一个符合某些要求的解. 八数码问题就是路径查找问题背景下的经典训练题目. 程序框架 p ...
- poj 3131 双向搜索+hash判重
题意: 初始状态固定(朝上的全是W,空格位置输入给出),输入初始状态的空格位置,和最终状态朝上的位置,输出要多少步才能移动到,超过30步输出-1. 简析: 每一个格子有6种状态,分别是 0WRB, 1 ...
- POJ1011【判重剪枝】
题意: 给你一堆棒子,这些棒子是你从一堆一样的棒子折断而来的, 现在你忘记了是从那一堆一样的棒子的长度,让你写一个程序,求最短的长度. 思路: 首先这个棒长肯定是和的约数,且大于最大值. 然后是sor ...
- BFS+Hash(储存,判重) HDOJ 1067 Gap
题目传送门 题意:一个图按照变成指定的图,问最少操作步数 分析:状态转移简单,主要是在图的存储以及判重问题,原来队列里装二维数组内存也可以,判重用神奇的hash技术 #include <bits ...
随机推荐
- 新浪 股票 API
新浪期货数据接口 [例子]http://hq.sinajs.cn/list=M0豆粕连续 M0 返回值如下:var hq_str_M0="豆粕连续,145958,3170,3190,3145 ...
- mac brew install 搭建nginx php mysql
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1 参考 : ...
- php 备份数据库
<?php header("Content-type:text/html;charset=utf-8"); //配置信息 $cfg_dbhost = 'loca ...
- 【Loadrunner】初学Loadrunner——录制脚本、回放、以及优化
一.脚本录制(录制) 打开Loadrunner > 选择创建/编辑脚本 > NewScript > 选择协议(单协议.多协议) > Strart Recording >选 ...
- easyui-datagrid加载时的效率低下,解决方案
在360浏览器中 使用easyui datagrid 加载数据是效率低下,有时候会出现卡机. 可以修改easyui源码进行解决.
- JavaScript(5)——DOM
DOM操作 为了写这一篇随笔真的是费了好多力气,虽然还是写不好.本来是从周一都开始写的,但是周二周三忙着去帮忙招新了,哈哈哈.感觉做自己喜欢的事特别好玩,虽然挺忙的.看着那些小鲜肉,感觉自己真的老了啊 ...
- cocoaPods的安装方法
1.打开终端 2.先升级Gem sudo gem update --system 3.切换cocoapods的数据源 [先删除,再添加,查看] gem sources --remove https:/ ...
- HDU 5826 physics
该问题和xi,di均无关,碰撞只会使得速度反向,大小不会变.因此只要计算速度. #pragma comment(linker, "/STACK:1024000000,1024000000&q ...
- mongodb 数据库导入.cvs文件时某些字段类型变成NumberLong的解决办法
在mongodb中导入数据时,会在数据库中生成字段记录为NumberLong的数据,可以使用以下方式将其转换为String db.Account.find().forEach( function(it ...
- js 条件判断放大字体
<html> <head> <meta charset="utf-8" /> <title></title> <s ...