【hdu 1429】胜利大逃亡(续)
【Link】:
【Description】
给你一个n*m的格子;
里面有钥匙,以及钥匙能开的门;
以及墙,以及起点,以及出口;
问你从起点出发,到出口的话,能不能在t时间内到;
【Solution】
dis[x][y][sta]表示到了点(x,y)然后拥有钥匙的状态为sta的最短时间花费;
sta用10位的二进制表示;
根据sta判断能不能接着往下走,以及能不能打开某一扇门;
以及获取新的钥匙
到了终点,就记录f的最小值;
【NumberOf WA】
1
【Reviw】
【Code】
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {-1,0,0,1,0};
const int INF = 0x3f3f3f3f;
struct node{
int x,y,sta;
};
char s[N+5][N+5];
int a[N+5][N+5],n,m,t,Sx,Sy,Tx,Ty;
int dis[N+5][N+5][1024],two[12];
queue <node> dl;
node temp;
bool bfs(){
while (!dl.empty()) dl.pop();
dis[Sx][Sy][0] = 0;
temp.x = Sx,temp.y = Sy,temp.sta = 0;
dl.push(temp);
int mi = INF;
while (!dl.empty()){
temp = dl.front();
dl.pop();
int x = temp.x, y = temp.y,tsta = temp.sta,sta;
if (x==Tx && y==Ty) mi = min(mi,dis[x][y][tsta]);
for (int i = 0; i<= 3;i++){
int tx = x + dx[i],ty = y + dy[i];
if (tx<1 || tx > n || ty<1|| ty>m) continue;
if (a[tx][ty]==0) continue;
if (a[tx][ty]==100 || (a[tx][ty]>=1 && a[tx][ty]<=10)){
if (a[tx][ty]!=100)
sta = tsta|two[a[tx][ty]-1];
else
sta = tsta;
if (dis[tx][ty][sta]==-1 || dis[tx][ty][sta]>dis[x][y][tsta]+1){
dis[tx][ty][sta] = dis[x][y][tsta]+1;
temp.x = tx,temp.y = ty,temp.sta = sta;
dl.push(temp);
}
}
if (a[tx][ty]>=11 && a[tx][ty]<=20){
sta = tsta;
int temp1 = a[tx][ty]-11;
if (two[temp1]&sta){
if (dis[tx][ty][sta]==-1 || dis[tx][ty][sta]>dis[x][y][tsta]+1){
dis[tx][ty][sta] = dis[x][y][tsta]+1;
temp.x = tx,temp.y = ty,temp.sta = sta;
dl.push(temp);
}
}
}
}
}
if (mi==INF) return false;
if (mi>=t) return false;
printf("%d\n",mi);
return true;
}
int main(){
//freopen("F:\\rush.txt","r",stdin);
two[0] = 1;
for (int i = 1;i <= 10;i++) two[i] = two[i-1]*2;
while (~scanf("%d%d%d",&n,&m,&t)){
memset(dis,255,sizeof dis);
for (int i = 1;i <= n;i++)
scanf("%s",s[i]+1);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++){
if (s[i][j]=='@'){
Sx = i,Sy = j;
a[i][j] = 100;
}
if (s[i][j]>='A' && s[i][j]<='Z'){
a[i][j] = s[i][j]-'A'+1+10;
}
if (s[i][j]>='a' && s[i][j]<='z'){
a[i][j] = s[i][j]-'a'+1;
}
if (s[i][j]=='^'){
Tx = i,Ty = j;
a[i][j] = 100;
}
if (s[i][j]=='*'){
a[i][j] = 0;
}
if (s[i][j]=='.'){
a[i][j]=100;
}
}
if (!bfs()) puts("-1");
}
return 0;
}
【hdu 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 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- 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+位压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU 1429 胜利大逃亡(续)(DP + 状态压缩)
胜利大逃亡(续) Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢 ...
- HDU 1429 胜利大逃亡(续)(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 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+状态压缩)
Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带 ...
随机推荐
- vue组件的一些知识理解
组件我们在项目中会很常用到,说下自己在学习过程中的理解,有关 组件初始化顺序,组件为什么data是function,组件的生命周期 1. Vue.component('', {}) 注册全局组件,组 ...
- 设置和获取Android中各种音量
通过程序获取android系统手机的铃声和音量.同样,设置铃声和音量的方法也很简单! AudioManager am = (AudioManager) getSystemService(Context ...
- jquery一些总结
今天用jquery写一个js的效果,总结了几个方法. 获取jquery对象的css样式属性:css()方法,还可以更改其css样式:$(this).css('display') ;$(this).cs ...
- BZOJ 3674: 可持久化并查集模板
Code: #include <cstdio> #include <algorithm> #include <cstring> #include <strin ...
- iOS开发——捕获崩溃信息
可通过注册NSUncaughtExceptionHandler捕获异常信息,将拿到的NSException细节写入Crash日志,精准的定位出错程序位置,有需要的,可直接将crash信息直接上传服务器 ...
- Open With Atom添加到右键菜单/从右键菜单移除
1.进入Settings 快捷键ctrl+shift+p,输入settings后回车 2.切换到System选项卡 3.通过勾选/取消勾选以下选项实现添加/移除右键菜单 √ Show in file ...
- php如何openssl_encrypt加密解密
最近在对接客户的CRM系统,获取令牌时,要用DES方式加密解密,由于之前没有搞错这种加密方式,经过请教了"百度"和"谷歌"两个老师后,结合了多篇文档内容后,终于 ...
- CMSIS-RTOS 时间管理之时间延迟Time Delay
时间管理 Time Management 此RTOS除了可以把你的应用代码作为线程运行,它还可以提供一些时间服务功能,使用这些功能你就可以访问RTOS的一些系统调用. 时间延迟Time Delay 在 ...
- 洛谷 P3068 [USACO13JAN]派对邀请函Party Invitations
P3068 [USACO13JAN]派对邀请函Party Invitations 题目描述 Farmer John is throwing a party and wants to invite so ...
- Vmware qemu-kvm 虚拟化測试
[root@kvm1 cloud]# lsmod | grep kvm kvm_intel 55496 3 kvm 337772 1 kvm_intel [root@kvm1 cloud]# egre ...