Description

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

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

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with two space-separated integers h and w (3 ≤ hw ≤ 100): the height and width of the maze, respectively.

  • h lines, each with w 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.

Sample Input

3
FFRBLF
FFRFRBRFBFRBRFLF
FRLFFFLBRFFFRFFFRFRFBRFLBRFRLFLFFR

Sample Output

3
4 4
####
...#
##.#
####
7 5
#####
...##
##.##
#...#
##.##
##.##
#####
7 7
#######
#...#.#
#.#...#
#.#.###
..###.#
#.....#
#######

 
这道题就很妙,给出操作复原图,不过有几个注意的点,我们很容易可以想到偏移坐标,来求解,但千万得注意,一开始就要标记起点,为什么?这是入口啊兄弟,,,还要要输出测试数量,哎,没有看清题意,凉凉。
这是我的代码:
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define PY 100
#define INF 0x3f3f3f3f
bool book[][];
char ch[];
int main()
{
int n; scanf("%d",&n); printf("%d\n",n);
while(n--)
{
memset(book,,sizeof(book));
getchar();
scanf("%s",ch);
int i=;
int nowx=+PY;
int nowy=+PY;
int miny=PY,maxy=PY,maxx=PY,minx=PY;
int t=;//东
book[nowx][nowy]=; while(ch[i]!='\0')
{
if(ch[i]=='F')
{
if(t==)
{
nowy++; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
if(t==)
{
nowx++; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
if(t==)
{
nowy--; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
if(t==)
{
nowx--; book[nowx][nowy]=;
// printf("%d %d\n",nowx,nowy);
} }
if(ch[i]=='B')
{
if(t==)
{
t=;
nowy--; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;
nowx--; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy); }
else if(t==)
{
t=;
nowy++; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;
nowx++; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
}
if(ch[i]=='R')
{
if(t==)
{
t=;//南
nowx++; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;//西
nowy--; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;//北
nowx--; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;
nowy++; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
}
if(ch[i]=='L')
{
if(t==)
{
t=;
nowx--; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;
nowy++; book[nowx][nowy]=;
// printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;
nowx++; book[nowx][nowy]=;
// printf("%d %d\n",nowx,nowy);
}
else if(t==)
{
t=;
nowy--; book[nowx][nowy]=;
//printf("%d %d\n",nowx,nowy);
}
}
i++;
minx=min(minx,nowx);
maxx=max(maxx,nowx);
miny=min(miny,nowy);
maxy=max(maxy,nowy);
}
int m=maxy-miny++;int n=maxx-minx++; printf("%d %d\n",n,m);
for(int i=minx- ; i<=maxx+ ;i++)
{
for(int j=miny ;j<=maxy+ ; j++)
if(book[i][j]==)
putchar('.');
else
putchar('#');
puts("");
} }
return ;
}

这是大佬的代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int net[][]={{,},{,},{,-},{-,}};
bool book[][];
char ch[];
int main()
{
int t;
scanf("%d",&t);
printf("%d\n",t);
while(t--)
{
memset(book,,sizeof(book));
scanf("%s",ch);
int n=strlen(ch);
int r=;
int nowx,nowy,maxy,miny,maxx,minx;
nowx=nowy=maxy=miny=maxx=minx=;
book[nowx][nowy]=;
for(int i= ; i<n ; i++)
{
if(ch[i]=='F')
{
nowx+=net[r][];
nowy+=net[r][];
book[nowx][nowy]=; }
else if(ch[i]=='R')
{
r=(r+)%;
nowx+=net[r][];
nowy+=net[r][];
book[nowx][nowy]=;
}
else if(ch[i]=='B')
{
r=(r+)%;
nowx+=net[r][];
nowy+=net[r][];
book[nowx][nowy]=;
}
else if(ch[i]=='L')
{
r=(r+)%;
nowx+=net[r][];
nowy+=net[r][];
book[nowx][nowy]=;
}
maxx=max(nowx,maxx);
minx=min(nowx,minx);
maxy=max(nowy,maxy);
miny=min(nowy,miny);
}
printf("%d %d\n",maxx-minx+,maxy-miny+);
for(int i=minx- ; i<=maxx+ ; i++)
{
for(int j=miny ; j<=maxy+ ; j++)
if(book[i][j]==)
printf(".");
else
printf("#");
printf("\n");
} } return ;
}

看到了吗,同样的一道问题的区别,虽然我的代码快一点点,然并软。

来简单分析下大神与我的区别1:我是根据方向来确定下一点。大神是根据点来确定方向,这就是个本质的区别,还是要多学习人家好的代码

Jury Jeopardy (这是一道单纯的模拟题)的更多相关文章

  1. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  2. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  3. ZOJ1111:Poker Hands(模拟题)

    A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...

  4. POJ 3923 Ugly Windows(——考察思维缜密性的模拟题)

    题目链接: http://poj.org/problem?id=3923 题意描述: 输入一个n*m的屏幕 该屏幕内有至少一个对话框(每个对话框都有对应的字母表示) 判断并输出该屏幕内处于最表层的对话 ...

  5. POJ 1008 简单模拟题

    e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...

  6. NOIP模拟题汇总(加厚版)

    \(NOIP\)模拟题汇总(加厚版) T1 string 描述 有一个仅由 '0' 和 '1' 组成的字符串 \(A\),可以对其执行下列两个操作: 删除 \(A\)中的第一个字符: 若 \(A\)中 ...

  7. POJ - 1835 宇航员(模拟题)

    问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...

  8. NOIP 模拟题

    目录 T1 : grid T2 : ling T3 : threebody 数据可私信我. T1 : grid 题目:在一个\(n*n\)的方格中,你只能斜着走.为了让问题更简单,你还有一次上下左右走 ...

  9. 9.28NOIP模拟题

    9.28NOIP模拟题 题目 哈 哈哈 哈哈哈 英文题目与子目录名 ha haha hahaha 单个测试点时间限制 1秒 1秒 1秒 内存限制 256M 128M 64M 测试点数目 10 10 1 ...

随机推荐

  1. 【266】增加bash文件的执行权限

    正常需要通过[bash pass.sh]来执行文件,但是可以通过增加bash文件的执行权限实现通过[./pass.sh]或者[pass.sh]来执行文件. 方法:通过chmod来增加权限,下面四种方法 ...

  2. Oracle pl/sql 显示游标和隐式游标

    显示游标 一.定义语法:        CURSOR <游标名> IS         <SELECT 语句>         [FOR UPDATE | FOR UPDATE ...

  3. sqlserver 查询int类型 in (字符串) 报转换int类型出错的问题

    , , '') ) AS c_departNames FROM t_user AS A LEFT JOIN t_role AS B ON A.c_roleId=B.c_roleId 用 CHARIND ...

  4. Codeforces Good Bye 2018 D (1091D) New Year and the Permutation Concatenation

    题意:给n!个n的排列,按字典序从小到大连成一条序列,例如3的情况为:[1,2,3, 1,3,2, 2,1,3 ,2,3,1 ,3,1,2 ,3,2,1],问其中长度为n,且和为sum=n*(n+1) ...

  5. vue 滚动加载数据

    参考链接:https://www.npmjs.com/package/vue-infinite-scroll

  6. php学习笔记-while循环

    while(condition) { func(); //break the loop } while循环的执行顺序是先判断condition是不是true,如果是true,那么就执行while循环体 ...

  7. Android 菜单 之 上下文菜单ContextMenu

    所谓上下文菜单就是当我们长按某一个文件时弹出的菜单 操作这个菜单我们要重写onCreateContextMenu()方法 如上一篇文章一样,对于这个菜单中选型的操作也有动态添加和xml文件添加两种方法 ...

  8. 100741A Queries

    传送门 题目 Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my f ...

  9. CF 959E Mahmoud and Ehab and the xor-MST

    第一反应是打表找规律……(写了个prim)但是太菜了没找到 于是开始怀疑是不是我的表错了,又写了一个克鲁斯卡尔,然后结果是一样的……(捂脸) 后来从克鲁斯卡尔的算法上发现了一点东西,发现只有2的幂次长 ...

  10. Pull项目失败

    1.网速原因 2.提示邮箱失效. 邮箱失效:解决方案 File->Setting: 然后,要记得重启,IDEA. 然后,在终端输入:git branch -l 查看项目分支 这样,设置好了用户名 ...