hdu 1429
http://acm.hdu.edu.cn/showproblem.php?pid=1429
一个广搜的简单题吧,不过有意思的事这个题目用到了位运算,还有就是很恶心的MLE
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std; int m,n,t;
char graph[][];
bool vis[][][<<];
int dic[][] = {-,,,,,-,,};
struct note{ int x,y,state,time; }loc;
queue<note>s;
/*
位运算就是在下面,对于每一个钥匙用二进制的0,1来存
*/
int bfs(int x,int y)
{
while(!s.empty())
s.pop();
loc.state = ;
loc.time = ;
loc.x = x;
loc.y = y;
s.push(loc);
while(!s.empty())
{
note fa,son;
fa = s.front();
s.pop();
// if(fa.time == t) return -1;
for(int i = ; i < ; i++)
{
son.x = fa.x + dic[ i ][ ];
son.y = fa.y + dic[ i ][ ];
if(son.x < || son.y < || son.y > n || son.x > m||!vis[son.x][son.y][fa.state]) continue; //这一行很关键,没有这一行就是MLE
if(graph[son.x][son.y] == '^')
{
if(fa.time == t ) return -;
else return fa.time;
}
if(graph[son.x][son.y] >='a'&& graph[son.x][son.y] <='z' &&vis[son.x][son.y][fa.state| ( <<(graph[son.x][son.y]-'a'))])
{
son.state = fa.state | ( <<(graph[son.x][son.y]-'a'));
son.time = fa.time+;
vis[son.x][son.y][son.state] = false;
s.push(son);
}
else if(graph[son.x][son.y]<='Z' && graph[son.x][son.y] >='A' && fa.state & ( << graph[son.x][son.y]-'A') &&vis[son.x][son.y][fa.state])
{
son.state = fa.state;
son.time = fa.time+;
vis[son.x][son.y][son.state] = false;
s.push(son);
}
else if(graph[son.x][son.y]=='.'||graph[son.x][son.y]=='@'&&vis[son.x][son.y][fa.state])
{
son.state = fa.state;
son.time = fa.time + ;
vis[son.x][son.y][son.state] = false;
s.push(son);
}
}
}
return -;
} int main()
{
// freopen("in.txt","r",stdin);
int x,y;
while(~scanf("%d%d%d",&m,&n,&t))
{
getchar(); //吃掉一个换行符
memset(graph,,sizeof(graph));
memset(vis,true,sizeof(vis));
int ans;
for(int i = ; i <= m; i++)
{
for(int j = ; j <= n ; j++)
{
scanf("%c",&graph[i][j]);
if(graph[i][j]=='@')
x = i,y = j;
}
getchar();
}
ans = bfs(x,y);
printf("%d\n",ans);
}
return ;
}
hdu 1429的更多相关文章
- HDU 1429 (BFS+记忆化状压搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1429 题目大意:最短时间内出迷宫,可以走回头路,迷宫内有不同的门,对应不同的钥匙. 解题思路: 要是 ...
- hdu 1429 胜利大逃亡(续)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...
- hdu 1429 (bfs+状态压缩) 胜利大逃亡续
http://acm.hdu.edu.cn/showproblem.php?pid=1429 典型的状压搜索,在普通的搜索基础上,利用二进制的特性记录钥匙与门, 二进制的每一位代表一把钥匙,比如说拿到 ...
- HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- hdu - 1429 胜利大逃亡(续) (bfs状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=1429 终于开始能够做状态压缩的题了,虽然这只是状态压缩里面一道很简单的题. 状态压缩就是用二进制的思想来表示状态 ...
- hdu.1429.胜利大逃亡(续)(bfs + 0101011110)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- hdu 1429 胜利大逃亡(续) (bfs+状态压缩)
又开始刷题了 题意:略过. 分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙.状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,k ...
- hdu 1429(bfs+状态压缩)
题意:容易理解,但要注意的地方是:如果魔王回来的时候刚好走到出口或还未到出口都算逃亡失败.因为这里我贡献了一次wa. 分析:仔细阅读题目之后,会发现最多的钥匙数量为10把,所以把这个作为题目的突破口, ...
随机推荐
- EntityFramework之监听者判断SQL性能指标
前言 当我们利用EF这个ORM框架时,我们可能会利用LINQ或者原生的SQL语句来进行数据操作,此时我们无法确定我们的代码是否会给数据库带来一定的负载,当给数据库带来一定的压力时,由于项目中对数据进行 ...
- POI导出Excel并下载
首先在pom.xml添加jar包: <!-- 导出excel --> <dependency> <groupId>org.apache.poi</groupI ...
- 记一周cdqz训练
#include <cstdio> using namespace std; int main(){ puts("转载请注明出处:http://www.cnblogs.com/w ...
- windows使用git时出现:warning: LF will be replaced by CRLF
windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示: 执行以下代码 $ rm -rf .git // 删除.git $ git config -- ...
- ios相同版本升级
公司新发布ios,因为各种错误以及审核不通过造成app未能上传,而app在提交的时候不能上传相同的版本号,造成app还没有正式的上传上传已经将版本号升级到1.0.6 解决方法: 在Xcode上,查看项 ...
- c语言数据结构复习
1)线性表 //顺序存储下线性表的操作实现 #include <stdio.h> #include <stdlib.h> typedef int ElemType; /*线性表 ...
- Caf.CMS是一个免费的、 开源,功能齐全的CMS
Caf.CMS(疯狂蚂蚁CMS) 是一个免费的. 开源,功能全面的CMS(内容管理系统).定位CMS也有点狭义呢,因为Caf.CMS是基于国外SmartStore.NET 开源商城源码的基础上改造而成 ...
- 再谈 Mysql解决中文乱码
一是要把数据库服务器的字符集设置为 utf8. 数据库的字符集会跟服务器的字符集一起变化, 也会变成 utf8: 在/etc/my.cnf中, 的 [mysqld]中, 设置 character-se ...
- vim 标签页 tabnew 等的操作命令
对于vim这个 ide来说, 单纯的用 多子窗口 来操作, 感觉还是不够的, 还要结合标签页tab pages来,才能更好的操作. 所有关于标签 的 命令行 命令都是 以 :tab开始的, 可以用ta ...
- Tiny Mapper
今天看到一个对象映射工具-TinyMapper 1.介绍 Tiny Mapper是一个.net平台的开源的对象映射组件,其它的对象映射组件比如AutoMapper有兴趣的可以去看,Tiny Mappe ...