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. C#正则表达式匹配双引号

    html: <img class="bubble large" src="/images/hero-logos/cog.svg" width=" ...

  2. Libcurl 简明使用指南

    http://blog.csdn.net/weiling_shen/article/details/7620397 我们的程序中使用的是人家的Easy.h头文件.....完成文件的上传和下传. 尤其是 ...

  3. Entity Framework Tutorial Basics(20):Persistence in Entity Framework

    Persistence in Entity Framework There are two scenarios when persisting an entity using EntityFramew ...

  4. 形式化验证工具(PAT)2PC协议学习

    今天我们来看看2PC协议,不知道大家对2PC协议是不是了解,我们先简单介绍一下. 两阶段提交协议(two phase commit protocol, 2PC)可以保证数据的强一致性,许多分布式关系型 ...

  5. java全栈day08--面向对象

    今日内容介绍1.面向对象思想2.类与对象的二者关系3.局部变量和成员变量之间的关系4.封装的思想5.private,this关键字的用途6.案例 01面向对象和面向过程的思想 * A: 面向过程与面向 ...

  6. Python-第三方库requests详解(附requests中文官方教程)

    转自http://blog.csdn.net/cyjs1988/article/details/73294774 Python+requests中文官方教程: http://www.python-re ...

  7. socket网络服务实战

    一.epoll模型的构建 由于网络服务高并发的需求,一般socket网络模型都采用epoll模型,有关epoll模型的原理在相关论坛中有许多讲述,在此不做重复讲解,主要讲一讲epoll模型的封装实现. ...

  8. Django会话,用户和注册之用户认证

    通过session,我们可以在多次浏览器请求中保持数据, 接下来的部分就是用session来处理用户登录了. 当然,不能仅凭用户的一面之词,我们就相信,所以我们需要认证. 当然了,Django 也提供 ...

  9. UIPasteboard

    1.UIPasteboard 简介 顾名思义,UIPasteboard 是剪切板功能,因为 iOS 的原生控件 UITextField.UITextView.UIWebView, 我们在使用时如果长按 ...

  10. java volatile 关键字(转)

    volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果.在Java 5之后,volatile关键字才得以 ...