本文主要是介绍ACM Jury Jeopardy,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
What would a programming contest be without a problem featuring an ASCII-maze? Do not despair: one of the judges has designed such a problem.
The problem is about a maze that has exactly one entrance/exit, contains no cycles and has no empty space that is completely enclosed by walls. A robot is sent in to explore the entire maze. The robot always faces the direction it travels in. At every step, the robot will try to turn right. If there is a wall there, it will attempt to go forward instead. If that is not possible, it will try to turn left. If all three directions are unavailable, it will turn back.
The challenge for the contestants is to write a program that describes the path of the robot, starting from the entrance/exit square until it finally comes back to it. The movements are described by a single letter: 'F'
means forward, 'L'
is left, 'R'
is right and 'B'
stands for backward.Each of 'L'
, 'R'
and 'B'
does not only describe the change in orientation of the robot, but also the advancement of one square in that direction. The robot's initial direction is East. In addition, the path of the robot always ends at the entrance/exit square.
The judge responsible for the problem had completed all the samples and testdata, when disaster struck: the input file got deleted and there is no way to recover it! Fortunately the output and the samples are still there. Can you reconstruct the input from the output? For your convenience, he has manually added the number of test cases to both the sample output and the testdata output.
Input Format
On the first line one positive number: the number of test cases. After that per test case:
- one line with a single string: the movements of the robot through the maze.
Output Format
On the first line one positive number: the number of test cases, at most 100100. After that per test case:
- one line with two space-separated integers hh and ww (3 \le h, w \le 100)(3≤h,w≤100): the height and width of the maze, respectively.
- hh lines, each with ww characters, describing the maze: a
'#'
indicates a wall and a'.'
represents an empty square.
The entire contour of the maze consists of walls, with the exception of one square on the left: this is the entrance. The maze contains no cycles (i.e. paths that would lead the robot back to a square it had left in another direction) and no empty squares that cannot be reached from the entrance. Every row or column – with the exception of the top row, bottom row and right column – contains at least one empty square.
样例输入
3 FFRBLF FFRFRBRFBFRBRFLF FRLFFFLBRFFFRFFFRFRFBRFLBRFRLFLFFR
样例输出
3 4 4 #### ...# ##.# #### 7 5 ##### ...## ##.## #...# ##.## ##.## ##### 7 7 ####### #...#.# #.#...# #.#.### ..###.# #.....# #######
题意:
FRBL分别代表前右后左,给出每次不同的步骤,求出一个地图,这个地图的外围除了入口处全都是墙壁‘#’,道路用‘.’表示
分析;
难点就是每次的方向都是相对于当下的,也就是说不同的点出的next数组会不一样;我令FRBL分别为1234,next={{0,1},{1,0},{0,-1},{-1,0}},发现只要是顺时针转,每转90度,next数组的第一行变成最后一行,其余三行一次向上递增,则需要每次变换next数组;
代码:
#include<stdio.h>
#include<map>
#include<string.h>
#include<math.h>
using namespace std;
#define inf 99999999;
int k;
char mapp[210][105],s[10005];
map<char,int>mm;
int main()
{
int i,j,l,n,m,tx,ty,mayy,maxx,mixx;
scanf("%d",&k);
mm['F']=1;
mm['R']=2;
mm['B']=3;
mm['L']=4;
printf("%d\n",k);
while(k--)
{
int next[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
maxx=-1;
mayy=-1;
mixx=inf;
for(i=0;i<210;i++)
for(j=0;j<105;j++)
{
mapp[i][j]='#';
}
scanf("%s",s);
n=strlen(s);
mapp[105][0]='.';
tx=105;
ty=0;
for(i=0;i<n;i++)
{
tx=tx+next[mm[s[i]]-1][0];
ty=ty+next[mm[s[i]]-1][1];
maxx=max(maxx,tx);//记录下地图的最上方最下方以及最右方;
mayy=max(mayy,ty);
mixx=min(mixx,tx);
mapp[tx][ty]='.';
m=mm[s[i]]-1;
for(j=0;j<m;j++)//m表示 转过几个90度;
{
int a,b;
a=next[0][0];
b=next[0][1];
for(l=0;l<3;l++)
{
next[l][0]=next[l+1][0];
next[l][1]=next[l+1][1];
}
next[3][0]=a;
next[3][1]=b;
}
}
printf("%d %d\n",maxx-mixx+3,mayy+2);
for(i=mixx-1;i<=maxx+1;i++)
{
for(j=0;j<=mayy+1;j++)
{
printf("%c",mapp[i][j]);
}
printf("\n");
}
}
return 0;
}
这篇关于ACM Jury Jeopardy的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!