hdu 1429 胜利大逃亡(延续)(BFS+比特压缩)
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int n,m,t,vis[25][25][1024];
char mp[25][25];
int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};
struct node
{
int x,y,t,k;
} p1,p2;
int bfs(int sx,int sy,int ex,int ey)
{
int i,j,flag=0;
queue<node>q;
p1.x=sx;
p1.y=sy;
p1.t=0;
p1.k=0;
q.push(p1);
while(!q.empty())
{
p1=q.front();
q.pop();
//printf("%d %d\n",p1.x,p1.y);
if(p1.x==ex&&p1.y==ey)
{
flag=p1.t;
break;
}
for(i=0; i<4; i++)
{
p2.x=p1.x+dx[i];
p2.y=p1.y+dy[i];
p2.t=p1.t+1;
p2.k=p1.k;
if(p2.x<0||p2.x>=n||p2.y<0||p2.y>=m) continue;
if(mp[p2.x][p2.y]=='*') continue;
if(mp[p2.x][p2.y]<='J'&&mp[p2.x][p2.y]>='A')
{
int k=p2.k&(1<<mp[p2.x][p2.y]-'A');
if(!k) continue;
}
if(mp[p2.x][p2.y]<='j'&&mp[p2.x][p2.y]>='a')
{
p2.k=p2.k|(1<<(mp[p2.x][p2.y]-'a'));
}
while(vis[p2.x][p2.y][p2.k]==0)
{
vis[p2.x][p2.y][p2.k]=1;
q.push(p2);
}
}
}
if(flag>=t||flag==0) flag=-1;
return flag;
}
int main()
{
int i,j,sx,sy,ex,ey,flag;
while(~scanf("%d%d%d",&n,&m,&t))
{
memset(vis,0,sizeof(vis));
for(i=0; i<n; i++)
scanf("%s",mp[i]);
for(i=0; i<n; i++)
for(j=0; j<m; j++)
{
if(mp[i][j]=='@')
{
sx=i;
sy=j;
mp[i][j]='.';
}
if(mp[i][j]=='^')
{
ex=i;
ey=j;
}
}
printf("%d\n",bfs(sx,sy,ex,ey));
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。http://xiang578.top/
hdu 1429 胜利大逃亡(延续)(BFS+比特压缩)的更多相关文章
- hdu 1429 胜利大逃亡(续)(bfs+位压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu - 1429 胜利大逃亡(续) (bfs状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=1429 终于开始能够做状态压缩的题了,虽然这只是状态压缩里面一道很简单的题. 状态压缩就是用二进制的思想来表示状态 ...
- hdu 1429 胜利大逃亡(续) (bfs+状态压缩)
又开始刷题了 题意:略过. 分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙.状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,k ...
- hdu.1429.胜利大逃亡(续)(bfs + 0101011110)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDOJ 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 胜利大逃亡(续)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...
- HDU 1429 胜利大逃亡(续)(bfs)
胜利大逃亡(续) 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 ...
随机推荐
- E. Mike and Foam(容斥原理)
E. Mike and Foam Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special sh ...
- Linux 核心阅读工具vim+ctags+cscope+taglist
今天.介绍vim+ctags+cscope+taglist的内核阅读配置. 当使用过之后,我相信大部分人都会舍弃之前的Eclipse(我就是活生生的一个样例).我们先来看看实现的界面是怎么样的: 我们 ...
- VSTO学习笔记(二)Excel对象模型
原文:VSTO学习笔记(二)Excel对象模型 上一次主要学习了VSTO的发展历史及其历代版本的新特性,概述了VSTO对开发人员的帮助和效率提升.从这次开始,将从VSTO 4.0开始,逐一探讨VSTO ...
- wpf dll和exe合并成一个新的exe
原文:wpf dll和exe合并成一个新的exe 微软有一个工具叫ILMerge可以合并dll exe等,但是对于wpf的应用程序而言这个工具就不好用了.我的这方法也是从国外一个博客上找来的.仅供大家 ...
- 【IOS实例小计】今日开贴,记录我的ios学习生涯,留下点滴,留下快乐,成荫后人。
今天开贴来记录自己的ios学习过程,本人目前小白一个,由于对ios感兴趣,所以开始学习,原职java程序,呵呵,勿喷. 本次的[ios实例小计]主要参考一文http://blog.sina.com.c ...
- Axure RP 实践.1
工作需要设计产品原型,找来Axure RP帮忙,看了一些文章,其中下面这段话深得我心. “只使用Axure的默认控件(Wireframe),不要用那些样式花哨的自定义控件,并且所有页面中使用的颜色不能 ...
- mac和windows系统下 eclipse svn 设置代理服务器
公司svn服务器在海外,有时候迫不得已svn也得设置代理 网上查了好长时间都只有windows下如何设置,mac系统下的教程很少. 1.在windows下设置方法如下 找到C:\Documentsan ...
- cocoapod安装失败解决
cocoapods 是 iOS 上不错的包依赖管理软件,在前面的文章里衣服自己洗是有做简单的介绍.最近在学习iOS开发,中间碰到安装cocoapods一些问题,具体的安装教程网上非常多,大家搜一下久可 ...
- start_kernel——boot_init_stack_canary
/* * Initialize the stackprotector canary value. * * NOTE: this must only be called from functions t ...
- mysql5.1,5.5,5.6做partition时支持的函数
mysql5.1支持的partition函数(http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations-functions.htm ...