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.
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.
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 ≤ h, w ≤ 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.
3
FFRBLF
FFRFRBRFBFRBRFLF
FRLFFFLBRFFFRFFFRFRFBRFLBRFRLFLFFR
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 (这是一道单纯的模拟题)的更多相关文章
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- ZOJ1111:Poker Hands(模拟题)
A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...
- POJ 3923 Ugly Windows(——考察思维缜密性的模拟题)
题目链接: http://poj.org/problem?id=3923 题意描述: 输入一个n*m的屏幕 该屏幕内有至少一个对话框(每个对话框都有对应的字母表示) 判断并输出该屏幕内处于最表层的对话 ...
- POJ 1008 简单模拟题
e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...
- NOIP模拟题汇总(加厚版)
\(NOIP\)模拟题汇总(加厚版) T1 string 描述 有一个仅由 '0' 和 '1' 组成的字符串 \(A\),可以对其执行下列两个操作: 删除 \(A\)中的第一个字符: 若 \(A\)中 ...
- POJ - 1835 宇航员(模拟题)
问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...
- NOIP 模拟题
目录 T1 : grid T2 : ling T3 : threebody 数据可私信我. T1 : grid 题目:在一个\(n*n\)的方格中,你只能斜着走.为了让问题更简单,你还有一次上下左右走 ...
- 9.28NOIP模拟题
9.28NOIP模拟题 题目 哈 哈哈 哈哈哈 英文题目与子目录名 ha haha hahaha 单个测试点时间限制 1秒 1秒 1秒 内存限制 256M 128M 64M 测试点数目 10 10 1 ...
随机推荐
- jQuery-图片的放大镜显示效果(不需要大小图)
问题:当页面高度很大时,放大图片的图层不会跟随着 1.demo.html ;display:none;} #tip s {position:absolute;top:40px;l ...
- FileZilla Server下通过别名设置虚拟目录
说明:FileZilla Server 的虚拟目录设置与其它 FTP 服务器软件有所不同.在 FileZilla Server 中设置虚拟目录,必须采用 FTP 根目录 + 虚拟目录名的形式来进行.比 ...
- Node.js的__dirname,__filename,process.cwd(),./的含义
简单说一下这几个路径的意思,: __dirname: 获得当前执行文件所在目录的完整目录名 __filename: 获得当前执行文件的带有完整绝对路径的文件名 process.cwd():获得当前执行 ...
- Python 求和函数
#coding=utf-8 ########################### #求1到10,20到30,30到40之和 ########################### sum=0 for ...
- Linux 使用静态库注意事项
1. 静态库一定要放在生成文件后面 gcc main.c -o main libhello.a 2. 使用静态库时一定要连接所有用到的静态库 gcc main.c -o main liba.a lib ...
- JavaPersistenceWithMyBatis3笔记-第4章SQL Mappers Using Annotations-001
一. 1.Mapper /** * */ package com.mybatis3.mappers; import org.apache.ibatis.annotations.Select; impo ...
- 100722E The Bookcase
传送门 题目大意 给你一些书的高度和宽度,有一个一列三行书柜,要求放进去书后,三行书柜的高的和乘以书柜的宽度最小.问这个值最小是多少. 分析 我们可以先将所有书按照高度降序排好,这样对于每一层只要放过 ...
- windows7向github提交代码
首先要有一个github账号. 我自己申请了github账号,然后创建一个代码仓库. 这个是我创建好的代码仓库:里面是空的没有代码,我今天从我本地写好的代码,传到github上面去. 首先需要告诉gi ...
- 浅谈assert()函数的用法
#include<stdio.h> #include<assert.h> char * Strcpy(char *dst,const char *src) { assert(d ...
- 使用canvas压缩图片 并上传
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...