天神小学
时间限制(普通/Java) :
1000 MS/ 3000 MS 运行内存限制 : 65536 KByte
总提交 : 192 测试通过 : 66
总提交 : 192 测试通过 : 66
比赛描述
《corpse party:blood drive》中有这么一段,班长筱崎亚由美拿到六鬼门的晶石,导致了涅?的暴走,天小的崩溃,靠着幸子的力量才逃出了天小。(剧情什么的不重要)
现在我们假设没有幸子,班长需要靠自己的力量逃出天神小学。可以把天神小学看作是一个二维的迷宫,每一秒都只能从当前位置走到上下左右四个相邻的格子里,因为天小一直在崩溃,所以有很多点是无法行走的。问班长能不能在天小完全崩溃,即t秒内逃出天神小学。
输入
第一行一个整数T,表示数据组数
每组数据第一行输入3个整数n,m,t分别表示迷宫的行数,列数,以及距离天小崩溃剩余的时间。(3≤n,m≤20,t≤100)
接下来输入n行,每行有一个长度为m的字符串。
其中字符’.’表示可以通行
字符’*’表示无法通行
字符’O’表示出口
字符’X’表示班长的起始位置
输出
若能逃离 输出 "happy end"
否则输出 "bad end"
样例输入
2
5 5 13
.....
.***.
.*X*O
.*.*.
...*.
5 5 14
.....
.***.
.*X*O
.*.*.
...*.
样例输出
bad end
happy end
题目来源
kojimai
#include<iostream>
#include<queue>
using namespace std;
struct point{
int x,y;
};
int dirX[4]={-1, 1, 0, 0};
int dirY[4]={ 0, 0,-1, 1};
int main(){
// freopen("test.txt","r",stdin);
char a[20][20];
int T,n,m,t,i,j,k;
point p,levelEndP,tempP;
deque<point> pQueue;
cin>>T;
while(T--){
while(!pQueue.empty()){
pQueue.pop_back();
}
cin>>n>>m>>t;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]=='X'){
levelEndP.x = i;
levelEndP.y = j;
pQueue.push_back(levelEndP);
}
}
}
while(t){
if(pQueue.empty()){
t = 0;
break;
}
p = pQueue.front();
pQueue.pop_front();
for(k=0;k<4;k++){
i = p.x+dirX[k];
j = p.y+dirY[k];
if(a[i][j]=='O'){
break;
}else if(a[i][j]=='.'){
tempP.x = i;
tempP.y = j;
a[i][j] = '*';
pQueue.push_back(tempP);
}
}
if(k<4){ //WA
break;
}
if(levelEndP.x == p.x && levelEndP.y == p.y){
t--;
if(pQueue.empty()){
t = 0;
break;
}
levelEndP = pQueue.back();
}
}
if(t){
cout<<"happy end"<<endl;
}else{
cout<<"bad end"<<endl;
}
}
}