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 ...
随机推荐
- jsonp原来是这么回事,豁然开朗
什么是JSONP 先说说JSONP是怎么产生的: 其实网上关于JSONP的讲解有很多,但却千篇一律,而且云里雾里,对于很多刚接触的人来讲理解起来有些困难,小可不才,试着用自己的方式来阐释一下这个问题, ...
- 2016NEFU集训第n+5场 A - Chinese Girls' Amusement
Description You must have heard that the Chinese culture is quite different from that of Europ ...
- 关于WM_NCHITTEST消息
我为了移动一个无标题栏的窗体,使用了WM_NCHITTEST消息,这个消息大概如下: 通常,我们拖动对话框窗口的标题栏来移动窗口,但有时候,我们想通过鼠标在客户区上拖动来移动窗口. 一个容易想到的方案 ...
- Openjudge-计算概论(A)-回文串判断
描述: 任意给定一个非空的字符串,判断其是否是回文串.回文串是指正向看和反向看均相等的串,如AbcDcbA和cDDc.如果是回文串,则输出1,否则,输出0 输入长度不小于1不大于100的字符串输出如果 ...
- poj2386
湖计数描述由于最近的降雨,水汇集在不同的地方,在农民约翰的领域,这是代表一个长方形的N×M(1μ= 100:1 = M = 100)平方.每一方都包含水(’w')或干燥的土地(“.”).农民约翰想弄清 ...
- SSL+socket详解
转自:http://hengstart.iteye.com/blog/842529 一. SSL概述 SSL协议采用数字证书及数字签名进行双端实体认证,用非对称加密算法进行密钥协商,用对 ...
- phabricator 搭建
os:debian7 Installation Guide :https://secure.phabricator.com/book/phabricator/ $ cd /data # 安装目录 da ...
- LeetCode OJ 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...
- ios 烟花 火焰 雨水 雪花等特效属性
CAEmitterLayer *snowEmitter = [CAEmitterLayer layer]; //例子发射位置 snowEmitter.emitterPosition = CGPoint ...
- go:挂webserver
apache配置: <VirtualHost *:80> ServerName test.com DocumentRoot /home/q/system/Engine/src/biz/ww ...