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. java之类的封装

    类和对象成员变量,成员函数特殊的成员变量和成员函数 函数重载 构造函数 静态变量 静态函数面向对象:封装 继承 多态封装 Encapsulation为什么需要封装?外界无法直接操作对象的具体的属性(安 ...

  2. __call()和__callStatic()方法

    __call() 当对象访问不存在的方法时,__call()方法会被自动调用__callStatic() 当对象访问不存在的静态方法时,__callStatic()方法会被自动调用 这两个方法在PHP ...

  3. cocos2d-js 骨骼动画 3.10

    近期使用了cocos动画中的骨骼动画,这里记录使用的两种方式(3.10版): 一.cocos自带的动画编辑器导出的动画 ccs.armatureDataManager.addArmatureFileI ...

  4. iOS 本地加载js文件

    #import "RootViewController.h" @interface RootViewController ()<UIWebViewDelegate> @ ...

  5. Qt中显示图像的两种方法

    博客转载自:https://blog.csdn.net/lg1259156776/article/details/52325361 在Qt中处理图片一般都要用到QImage类,但是QImage的对象不 ...

  6. Spring第四篇

    在spring第三篇中介绍了bean元素属性 在第四篇中介绍spring注入的方式 1 set方法注入 建立一个User类 创建私有的属性 set  get 方法  重写toString方法 代码如下 ...

  7. Linux下性能监控工具介绍

    本章解释如何使用适用于Linux的大量性能工具及每个工具中信息的意义.即使已经使用top或者sar,也可能从本章学到相关知识. 应该养成使用这些工具的习惯.当然要知道如何诊断性能问题,但也应该定期寻找 ...

  8. HttpGet和HttpPost处理重定向的区别

    get方法默认会处理302的重定向,response获取到的页面其实是重定向以后的页面,通过response.getStatusLine(),取到的值是200. 通过设置可以用post方法去请求或者把 ...

  9. java多线程系列:通过对战游戏学习CyclicBarrier

    CyclicBarrier是java.util.concurrent包下面的一个工具类,字面意思是可循环使用(Cyclic)的屏障(Barrier),通过它可以实现让一组线程到达一个屏障(也可以叫同步 ...

  10. 国内物联网平台(1):百度物接入IoT Hub

    国内物联网平台(1) ——百度物接入IoT Hub 马智 物接入IoT Hub - 架构 全托管的云服务,帮助建立设备与云端之间安全可靠的双向连接 支撑海量设备的数据收集.监控.故障预测等各种物联网场 ...