胜利大逃亡(续)
来源:互联网 发布:java求100后第一个素数 编辑:程序博客网 时间:2024/06/05 22:47
传送门
胜利大逃亡(续)
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9005 Accepted Submission(s): 3244
Problem Description
Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)……
这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方。刚开始Ignatius被关在(sx,sy)的位置,离开地牢的门在(ex,ey)的位置。Ignatius每分钟只能从一个坐标走到相邻四个坐标中的其中一个。魔王每t分钟回地牢视察一次,若发现Ignatius不在原位置便把他拎回去。经过若干次的尝试,Ignatius已画出整个地牢的地图。现在请你帮他计算能否再次成功逃亡。只要在魔王下次视察之前走到出口就算离开地牢,如果魔王回来的时候刚好走到出口或还未到出口都算逃亡失败。
这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方。刚开始Ignatius被关在(sx,sy)的位置,离开地牢的门在(ex,ey)的位置。Ignatius每分钟只能从一个坐标走到相邻四个坐标中的其中一个。魔王每t分钟回地牢视察一次,若发现Ignatius不在原位置便把他拎回去。经过若干次的尝试,Ignatius已画出整个地牢的地图。现在请你帮他计算能否再次成功逃亡。只要在魔王下次视察之前走到出口就算离开地牢,如果魔王回来的时候刚好走到出口或还未到出口都算逃亡失败。
Input
每组测试数据的第一行有三个整数n,m,t(2<=n,m<=20,t>0)。接下来的n行m列为地牢的地图,其中包括:
. 代表路
* 代表墙
@ 代表Ignatius的起始位置
^ 代表地牢的出口
A-J 代表带锁的门,对应的钥匙分别为a-j
a-j 代表钥匙,对应的门分别为A-J
每组测试数据之间有一个空行。
. 代表路
* 代表墙
@ 代表Ignatius的起始位置
^ 代表地牢的出口
A-J 代表带锁的门,对应的钥匙分别为a-j
a-j 代表钥匙,对应的门分别为A-J
每组测试数据之间有一个空行。
Output
针对每组测试数据,如果可以成功逃亡,请输出需要多少分钟才能离开,如果不能则输出-1。
Sample Input
4 5 17@A.B.a*.*.*..*^c..b*4 5 16@A.B.a*.*.*..*^c..b*
Sample Output
16-1
Author
LL
Source
ACM暑期集训队练习赛(三)
Recommend
linle
题意:~~~中文题没啥说的。
主要这个钥匙的问题很烦。之前我想的是key[a][b][c] a b为当前的坐标 c为带的钥匙 假如得到了A钥匙就key[a][b][c-'a']++;
但仔细一想钥匙的状态可以压到26位(26个字母 而且可以携带这种状态 标记vis
//china no.1#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>using namespace std;#define pi acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,-1,-1,1,1};const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=1e5+100;const double EPS=1e-7;const int MOD=10000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)int n,m,t;char mapp[25][25];int stx,sty,edx,edy,ans;int key[maxn],vis[25][25][1<<10];struct node{ int r,c,t,k;};int bfs(){ queue<node >Q; Q.push({stx,sty,0,0}); W(!Q.empty()) { node temp=Q.front();Q.pop();node v; FOR(0,3,i) { int xx=temp.r+dx[i]; int yy=temp.c+dy[i]; if(xx<=0||xx>n||yy<=0||yy>m) continue; char c=mapp[xx][yy]; if(c=='*'||temp.t+1>=t) continue; v.t=temp.t+1,v.k=temp.k; v.r=xx;v.c=yy; if(c=='^') return v.t; if(c>='A'&&c<='Z') if((v.k&(1<<(c-'A')))==0) continue; if(c>='a'&&c<='z') v.k=(v.k|(1<<(c-'a'))); if(vis[v.r][v.c][v.k]) continue; vis[v.r][v.c][v.k]=1; Q.push(v); } } return -1;}int main(){ W(cin>>n>>m>>t) { me(vis); FOR(1,n,i) cin>>mapp[i]+1; FOR(1,n,i) FOR(1,m,j) { if(mapp[i][j]=='@') { stx=i;sty=j; } } cout<<bfs()<<endl; }}
阅读全文
0 0
- 胜利大逃亡(续)
- 胜利大逃亡(续)
- 胜利大逃亡(续)
- 胜利大逃亡(续)
- HDU1429 胜利大逃亡(续)
- hdu_1429 胜利大逃亡(续)
- hdu1429 胜利大逃亡(续)
- 胜利大逃亡(续)
- 胜利大逃亡(续) (bfs)
- HDU1429-胜利大逃亡(续)
- HDU1429-胜利大逃亡(续)
- Hdu1429 胜利大逃亡(续)
- 胜利大逃亡(续)
- HDU 1429 胜利大逃亡(续)
- 1429 胜利大逃亡(续)
- hdu 1429胜利大逃亡(续)
- hdu 1429 胜利大逃亡(续)
- HDU 1429 胜利大逃亡(续)
- java-day04-反射的运用
- IT牛人博客
- 第一章 设计模式入门之策略模式【C++11版】
- 【矩阵乘法】逆矩阵
- Apache Kafka
- 胜利大逃亡(续)
- DAY2T1
- 一张图理解prototype、proto和constructor的三角关系
- Android6.0新特性
- Windows服务
- XMAN2017选拔赛Web-variacover
- 适配器模式
- Java设计的银行取款系统-Mysql数据库(改进篇)2017/7/16
- 欢迎使用CSDN-markdown编辑器