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+ ...
随机推荐
- 关于Html基础语法学习
晚上做完初赛,好像有点颓,就来学了学html,毕竟博客里面会用到嘛. 首先贴出我所学习的教程 http://www.w3school.com.cn/html/index.asp 我觉得吧,可能以我的记 ...
- zgb老师关于java集合的总结
数组:存多个数据 操作不便集合(Collection ):存多个数据 管理多个数据 提供更为方便的操作Iterator:专门针对集合 进行迭代List:有序的 允许重复的元素ArrayList:底层数 ...
- Hadoop MapReduce编程 API入门系列之wordcount版本4(八)
这篇博客,给大家,体会不一样的版本编程. 是将map.combiner.shuffle.reduce等分开放一个.java里.则需要实现Tool. 代码 package zhouls.bigdata. ...
- 试图ddms 如果丢失adv链接解决办法!
点击如下图菜单 重启链接adv即可显示.
- Android网络编程随想录(3)
大多数Android的app都会使用HTTP协议来发送和接收数据.在Android开发中,通常使用两种http客户端:一个是Apache的HttpClient,另一个是HttpURLConnectio ...
- 单件模式(Singleton)C++实现
意图:保证一个类仅有一个实例,并提供一个访问它的全局访问点. 实用性:1.当类只能有一个实例而且客户可以从一个众所周知的访问点访问它. 2.当这个唯一的实例应该是通过子类可扩展的,并且客户应该无需更改 ...
- socket 的通信过程
1.建立套接字 Linux在利用socket()系统调用建立新的套接字时,需要传递套接字的地址族标识符.套接字类型以及协议,其函数定义于net/socket.c中: asmlinkage long s ...
- vc++如何创建程序01
1 .选择文件+新建(ctrl+N),然后选择一个空的工程,完成 2 然后在选择file新建,在files文件下面选择一个C++Source File,并取个文件名(比如为point可以不带.c) 我 ...
- windows 命令行 for 用法
for /r 目录名 %i in (匹配模式1,匹配模式2) do @echo %i for /r SATA %i in (*.txt) do @echo %i D:\REY\test>for ...
- ansible自动化部署
ansible通过模块实现批量管理及部署服务器,功能有模块实现 ansible无需在被控端安装agent/client,因为ansible是通过ssh分发ad-hoc(单条指令)或者palybook( ...