又开始刷题了

题意:略过。

分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙。状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,key|(x,y)表示捡起了一把钥匙。

错误:1、开标记数组mark[][][],key状态大小顺手开成key,其实应该是1<<key

2、判断应该先判wall(),顺序颠倒倒是RE(访问越界)

    3、key<=10:只有 a-j 共10种钥匙

思考:这道题其实应该是有漏洞的,因为魔王只是查看男主是否在原位置上,并没有说明检查钥匙,如此一来男主只要在时间限定T之内找到一把钥匙,就向逃亡迈进了一步,换句话说就是状态被大幅度增加——不再是必须在T内找到出口“^”。进一步说,若魔王发现男主不在原位置,不仅把他放回原位,还还原钥匙的位置,那么如果在时间限定T内,他能够找到钥匙并返回原位,又是否算是通过了这次检查呢?以上两种情况但凡一种成立,测试样例2都可以通过。

 #include<cstdio>
#include<cstring>
#include<cctype>
#include<queue>
#include<algorithm>
using namespace std; const int MAXN=;
const int KEY=; int dir[][]={,-,,,-,,,}; struct Node{
int x,y,t,key;
Node(){}
Node(int _x,int _y,int _t,int _key):x(_x),y(_y),t(_t),key(_key){}
}; char g[MAXN][MAXN];
int mark[MAXN][MAXN][<<KEY];
queue<Node>q; int n,m,T; bool wall(int x,int y)
{
if(x<||x>=n||y<||y>=m)
return true;
if(g[x][y]=='*')
return true;
return false;
} int Num(char ch)
{
return ch-(isupper(ch)?'A':'a');
} int bfs(int sx,int sy)
{
while(!q.empty())
q.pop(); memset(mark,,sizeof(mark));
q.push(Node(sx,sy,,));
while(!q.empty())
{
Node e=q.front();q.pop(); if(e.t>=T)
break; for(int i=;i<;i++)
{
int dx=e.x+dir[i][];
int dy=e.y+dir[i][];
int dt=e.t+;
int dkey=e.key; char ch=g[dx][dy]; if(wall(dx,dy))
continue;
if(dt>=T||mark[dx][dy][dkey])
continue;
if(isupper(ch)&&!(dkey&(<<Num(ch))))
continue;
if(islower(ch))
dkey=dkey|(<<Num(ch)); if(g[dx][dy]=='^')
return dt; mark[dx][dy][dkey]=;
q.push(Node(dx,dy,dt,dkey));
}
}
return -;
} int main()
{
while(~scanf("%d%d%d",&n,&m,&T))
{
for(int i=;i<n;i++)
scanf("%s",g[i]); int sx,sy,ex,ey;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(g[i][j]=='@'){
sx=i;
sy=j;
g[i][j]='.';
} printf("%d\n",bfs(sx,sy));
}
return ;
}

hdu 1429 胜利大逃亡(续) (bfs+状态压缩)的更多相关文章

  1. hdu - 1429 胜利大逃亡(续) (bfs状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=1429 终于开始能够做状态压缩的题了,虽然这只是状态压缩里面一道很简单的题. 状态压缩就是用二进制的思想来表示状态 ...

  2. hdu 1429 胜利大逃亡(续)(bfs+位压缩)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. HDOJ 1429 胜利大逃亡(续) (bfs+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 思路分析:题目要求找出最短的逃亡路径,但是与一般的问题不同,该问题增加了门与钥匙约束条件: 考虑 ...

  4. hdu.1429.胜利大逃亡(续)(bfs + 0101011110)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  5. HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

  6. hdu 1429 胜利大逃亡(续)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...

  7. HDU 1429 胜利大逃亡(续)(DP + 状态压缩)

    胜利大逃亡(续) Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢 ...

  8. HDU 1429 胜利大逃亡(续)(bfs)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. 胜利大逃亡(续)(状态压缩bfs)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

随机推荐

  1. codeforces 455B A Lot of Games(博弈,字典树)

    题目 参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269 //字典树,博弈 根据当前节点的后续来确定当前节点的状态, ...

  2. LCA(最近公共祖先)离线算法Tarjan+并查集

    本文来自:http://www.cnblogs.com/Findxiaoxun/p/3428516.html 写得很好,一看就懂了. 在这里就复制了一份. LCA问题: 给出一棵有根树T,对于任意两个 ...

  3. UITableView中cell的圆角(第一个和最后一个)

    , , _width, _height)];     ;     view.clipsToBounds = YES;          _viewDetal = [[UIView alloc]init ...

  4. Combination Sum III

    https://leetcode.com/problems/combination-sum-iii/ Find all possible combinations of k numbers that ...

  5. 在WCF中使用消息队列

    在一些大型的解决方案中,假设我们的服务没有办法一直在线,或者因为这样那样的原因宕机了,有没有什么办法让客户端的影响最小化呢?答案是可以通过消息队列的方式,哪怕服务是没有在线的,客户端依然可以继续操作. ...

  6. 传说中的WCF(11):会话(Session)

    在标题中我加了一个大家都很熟悉的单词——Session,熟吧?玩过Web开发的朋友肯定在梦中都会见到她. 在Web中为什么要会话呢?毕竟每个用户在一个Web应用中可能不止进行一次操作,比如,某二手飞机 ...

  7. lintcode :同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  8. Protobuf动态解析那些事儿

    需求背景 在接收到 protobuf 数据之后,如何自动创建具体的 Protobuf Message 对象,再做反序列化.“自动”的意思主要有两个方面:(1)当程序中新增一个 protobuf Mes ...

  9. HTML基本操作

    插入图片: 1.利用链接(静态) <img src="http://www.kmwzjs.com/useruploads/images/20101020_057600100825157 ...

  10. Girls: different perspectives to consider

    Girls: different perspectives to consider成为极品女人的十大要素The point of articles such as these isn't to dic ...