题目描述
解题思路
大模拟题
代码
#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
const int maxn = 1e5+7;
const int mod = 1e9+7;
#define ll long long
char mapp[55][55];
int n,m;
int stax, stay;
int v=0;
int dir=0;
char opp[505];
int dirxy[8][2]={-1,0, -1,1, 0,1, 1,1, 1,0, 1,-1, 0,-1, -1,-1};
int vxy[8][4]={
0,0,0,0,
-1,0,0,1,
0,0,0,0,
0,1,1,0,
0,0,0,0,
1,0,0,-1,
0,0,0,0,
0,-1,-1,0,
};
bool move(){
for(int step=0;step<v;step++){
int tx=stax+dirxy[dir][0];
int ty=stay+dirxy[dir][1];
//test crash
if(tx>n||tx<=0||ty>m||ty<=0){
return false;
}
if(mapp[tx][ty]=='#'){
return false;
}
if(dir==1||dir==3||dir==5||dir==7){
int xx = stax+vxy[dir][0];
int yy = stay+vxy[dir][1];
int xxx = stax+vxy[dir][2];
int yyy = stay+vxy[dir][3];
if(mapp[xx][yy]=='#'&&mapp[xxx][yyy]=='#'){
return false;
}
}
stax=tx;
stay=ty;
}
return true;
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d%d",&n,&m);
getchar();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%c", &mapp[i][j]);
if(mapp[i][j]=='*'){
stax=i;stay=j;
}
}
getchar();
}
int q;scanf("%d",&q);
//cout<<q<<endl;
scanf("%s",opp);
for(int i=0;i<q;i++){
char op = opp[i];
if(op=='U'){
v++;
}else if(op=='D'){
v--;
if(v<0)v=0;
}else if(op=='L'){
dir-=1;
if(dir==-1)dir=7;
}else{//op==R
dir+=1;
if(dir==8)dir=0;
}
// cout<<v<<" "<<dir<<"Aaa\n";
if(move()){
printf("%d %d\n", stax, stay);
}else{
printf("Crash! %d %d\n", stax, stay);
v=0;
}
}
return 0;
}