【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】胜利大逃亡(续)的更多相关文章

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

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

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

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

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

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

  4. 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 ...

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

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

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

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

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

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

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

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

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

    又开始刷题了 题意:略过. 分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙.状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,k ...

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

    Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带 ...

随机推荐

  1. sass10 demo1

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  2. 如何配置MySQL?(三)

    要进行mysql配置,首先要找到mysql的配置向导文件,这个配置向导文件就在我们安装目录下的一个bin的子目录下. 刚才我们是选择典型安装MySQL,一般windows是默认存储在C:\Progra ...

  3. WebView的坑[持续更新]

    返回错误的 innerHeight,如 240(WebView returns bad window.innerHeight) http://stackoverflow.com/questions/1 ...

  4. coedforces #481Div(3)(ABCDEFG)

    A. Remove Duplicates Petya has an array aconsisting of nintegers. He wants to remove duplicate (equa ...

  5. Python常用目录操作(Python2)

    Python获取当前路径   Python查看指定路径下的文件和文件夹 Python修改当前工作目录(在读取文件等时需要) Python添加import路径(有时候为了import自己写的py文件,且 ...

  6. UI Framework-1: views

    views Overview and background Windows provides very primitive tools for building user interfaces. Th ...

  7. 在 Ubuntu 18.04 LTS 无头服务器上安装 Oracle VirtualBox

    作者: Sk 译者: LCTT qhwdw | 2018-10-12 01:59 本教程将指导你在 Ubuntu 18.04 LTS 无头服务器上,一步一步地安装 Oracle VirtualBox. ...

  8. [HAOI2007][SDOI2005]反素数

    题目:洛谷P1463.BZOJ1053.Vijos P1172.codevs2912. 题目大意:对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x满足:g ...

  9. Ehcache学习总结(2)--Ehcache整合spring配置

    首先需要的maven依赖为: [html] view plain copy <!--ehcache--> <dependency> <groupId>com.goo ...

  10. Varnish 缓存加速, Varnish 菜鸟看过来,Varnish实战

    Varnish可以有效降低web服务器的负载,提升访问速度.按照HTTP协议的处理过程,web服务器接受请求并且返回处理结果,理想情况下服务器要在不做额外处理的情况下,立即返回结果,但实际情况并非如此 ...