hdoj--2579--Dating with girls(2)(搜索+三维标记)
Dating with girls(2)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2691 Accepted Submission(s): 752
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 next r line is the map’s description.
1
6 6 2
...Y..
...#..
.#....
...#..
...#..
..#G#.
7
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
//三维标记 ,当前的时间与t取余,到达"#"的时间只有t种,
//如果这几种都不行,那这条路就废了
char map[110][110];
int a[110][110][12];
int m,n,t;
int sx,sy;
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
struct node
{
int x,y,step;
friend bool operator < (node s1 ,node s2)
{
return s1.step>s2.step;
}
}p,temp;
void bfs()
{
memset(a,0,sizeof(a));
queue<node>q;
p.x=sx,p.y=sy;
p.step=0;
q.push(p);
a[sx][sy][0]=1;
while(!q.empty())
{
p=q.front();
q.pop();
if(map[p.x][p.y]=='G')
{
printf("%d\n",p.step);
return ;
}
for(int i=0;i<4;i++)
{
temp.x=p.x+dx[i];
temp.y=p.y+dy[i];
temp.step=p.step+1;
int d=temp.step%t;
if(temp.x<0||temp.x>=n||temp.y<0||temp.y>=m||a[temp.x][temp.y][d])
continue;
a[temp.x][temp.y][d]=1;
if(map[temp.x][temp.y]=='#'&&d)
continue;
q.push(temp);
}
}
printf("Please give me another chance!\n");
}
int main()
{
int s;
scanf("%d",&s);
while(s--)
{
scanf("%d%d%d",&n,&m,&t);
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();
}
return 0;
}
hdoj--2579--Dating with girls(2)(搜索+三维标记)的更多相关文章
- hdoj 2579 Dating with girls(2)【三重数组标记去重】
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2579 Dating with girls(2)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...
- hdu 2579 Dating with girls(2) (bfs)
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 【HDOJ】2579 Dating with girls(2)
简单BFS. /* 2579 */ #include <iostream> #include <queue> #include <cstdio> #include ...
- hdu 2578 Dating with girls(1) (hash)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 2578 Dating with girls(1) [补7-26]
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2578 Dating with girls(1)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...
- Dating with girls(1)(二分+map+set)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 3784 继续xxx定律 & HDU 2578 Dating with girls(1)
HDU 3784 继续xxx定律 HDU 2578 Dating with girls(1) 做3748之前要先做xxx定律 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ ...
随机推荐
- SQL server存储过程学习
由于之前使用 Linq to Sql来操作数据库,对于数据库的存储过程.函数等比较薄弱.乘着自己闲着的时候,就百度自学了一点存储过程,以防以后要用. 基础通俗易懂的存储过程通过 存储过程学习 ,然后自 ...
- JavaScript实现复选框的全选、不选、反选
方法一: <html> <head> <meta charset="utf-8"> <title>无标题文档</title&g ...
- 高德地图修改gps定位点样式
效果图 navi_map_gps_locked.png 图片1 图片2 修改 MyLocationStyle myLocationStyle = new MyLocationStyle();//初始化 ...
- Redis 四:存储类型之散列类型
1.散列类型表达方式简介: =========================================== 键 字段 值 =================================== ...
- 杭电2061WA 01
#include<stdio.h> struct mem { char s[50]; double c; double f; }; int main() { struct mem x[60 ...
- Python爬虫1-----urllib模块
1.加载urllib模块的request from urllib import request 2.相关函数: (1)urlopen函数:读取网页 webpage=request.urlopen(ur ...
- express get和post方法
把之前学习的一个小例子贴出来: 前提:需安装nodejs,可以在终端中输入node -v检查是否安装成功,安装成功后才可执行下面的步骤. 1.新建一个名称为“node”文件夹 2.进入node目录 ...
- P1892 团伙
题目描述 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么他们要么是朋友,要么是敌人.而且有一点是肯定的,就是: 我朋友的朋友是我的朋友: 我敌人的敌人也是我的朋友. 两个强盗是同一团伙的 ...
- 编写 Node.js Rest API 的 10 个最佳实践
Node.js 除了用来编写 WEB 应用之外,还可以用来编写 API 服务,我们在本文中会介绍编写 Node.js Rest API 的最佳实践,包括如何命名路由.进行认证和测试等话题,内容摘要如下 ...
- JSP中文乱码问题的由来以及解决方法
首先明确一点,在计算机中,只有二进制的数据! 一.java_web乱码问题的由来 1.字符集 1.1 ASCII字符集 在早期的计算机系统中,使用的字符非常少,这些字符包括26个英文字母.数字符号和一 ...