【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的地牢里,并在地牢的某些地方安装了带 ...
随机推荐
- TOMCATserver不写port号、不写项目名訪问项目、虚拟文件夹配置
一.不写port. 这个问题都被问烂了.由于TOMCAT默认的訪问port为8080.而TCP/IP协议默认80port訪问,大家之所以看到别的站点都不写port号是由于人家用的的80port訪问的, ...
- 在使用shape的同一时候,用代码改动shape的颜色属性
Android里面常常会使用shape来定制一些View的背景 能够改动View的背景颜色.形状等属性 普通情况下.shape都是在xml文件中面写死了.今天遇到一个需求,View的形状是圆角的,可是 ...
- IIS预编译提升载入速度
当我们把站点部署在IIS7或IIS6S的时候,每当IIS或是ApplicationPool重新启动后,第一次请求站点反应总是非常慢.原因大家都知道(不知道能够參考这个动画说明ASP.NET网页第一个R ...
- C++友元(Friend)简介
相对Java而言,友元是C++中特有的一种元素,再加上<C++ Primer>也并没有太具体的样例,所以刚接触这个概念的时候懵了非常久,即是自己总结一下,也希望能帮到大家,以下来讲讲友元的 ...
- Tomcat的安装跟配置
安装Tomcat的步骤:1)安装好JDK2)把tomcat-7.0.30软件解压到本地硬盘3)设置环境变量:JAVA_HOME: C:\Program Files\Java\jdk1.7.0_04To ...
- angularjs --- ngResource 类似于 ajax发送请求。
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- es6 --- class 类的继承使用
传统的javascript中只有对象,没有类的概念.它是基于原型的面向对象语言.原型对象特点就是将自身的属性共享给新对象.这样的写法相对于其它传统面向对象语言来讲,很有一种独树一帜的感脚!非常容易让人 ...
- ZoomIt(投影演示辅助软件)下载、安装与运行使用
下载ZoomIt后,打开即可使用:打开时,你讲看到如下的几个页面,这几个页面是为了介绍每个功能的使用,还可以去设定你觉得比较舒服的快捷键, 默认的是Ctrl+1屏幕放大.Ctrl+2屏幕标注,Ctrl ...
- WIFI 概览
概览 Android 提供默认 Android 框架实现,其中包括对各种 WLAN 协议和模式的支持,这些协议和模式包括: WLAN 基础架构 (STA) 网络共享模式或仅限本地模式下的 WLAN ...
- [ZJOI2012]旅游 对偶图 树的直径
Code: // luogu-judger-enable-o2 #include<cstdio> #include<iostream> #include<algorith ...