The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field.
题目大意:一个superman,以肉身合道 (刚火车) superman 先走,ta可以向前走一步再调整位置,然后火车向他的方向走二步,看看ta是否能到达边缘。
嗯,转化一下,都是superman在走,所以ta先走一步再枚举方向再走二步。然后就可以搜索了
#include<iostream>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cctype>
#define inf 0x3f3f3f3f
using namespace std;
typedef pair<int,int> pi;
char gap[5][150];
int visit[5][150];
int n,k;
pi s;
bool bfs()
{
queue<pi> q;
q.push(s);
while(!q.empty())
{
int x=q.front().first,y=q.front().second;
q.pop();
if(y>=n)
{
return 1;
}
if(isalpha(gap[x][++y])) continue;
for(int i=-1;i<=1;i++)
{
//cout<<"x";
int tempx=x+i;
if(tempx<1||tempx>3) continue;
if(isalpha(gap[tempx][y])||isalpha(gap[tempx][y+1])||isalpha(gap[tempx][y+2])||visit[tempx][y+2]==1)continue;
visit[tempx][y+2]=1;
if(y+2>=n) return 1;
q.push(pi(tempx,y+2));
}
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(visit,0,sizeof(visit));
scanf("%d%d",&n,&k);
for(int i=1;i<=3;i++)
{
scanf("%s",gap[i]+1);
if(gap[i][1]=='s') s.first=i,s.second=1;
}
visit[s.first][s.second]=1;
puts(bfs() ? "YES" : "NO");
}
}
游戏“Subway Roller”的通关搜索问题
博客介绍了移动应用商店的新游戏“Subway Roller”,游戏主角Philip在隧道中,隧道是三行n列矩形区域,有火车驶向主角。题目可转化为superman移动问题,先走一步再枚举方向走二步,然后进行搜索。
671

被折叠的 条评论
为什么被折叠?



