Benelux Algorithm Programming Contest 2014 Final: J. 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)(3h,w100): 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
#######
#...#.#
#.#...#
#.#.###
..###.#
#.....#
#######

跟着提议模拟模拟,它咋说你咋写就管

要注意,输出第一行是总数居的个数。。。忘记输出这个了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<n<<endl; 
	while(n--){
		int ma[500][500]={0};
		int x=200,y=0;
		ma[x][y]=1;
		int shang=0,xia=0,zuo=0,you=0;
		you=1;
		char s[20000];
		scanf("%s",s);
		queue<char> que;
		for(int i=0;i<strlen(s);i++){
			que.push(s[i]);
		}
		while(que.size()){
			char c=que.front();
			que.pop();	
			if(c=='F'){	
				if(you==1){
					ma[x][y+1]=1;
					y=y+1;
				}
				else if(zuo==1){
					ma[x][y-1]=1;
					y=y-1;
				}
				else if(shang==1){
					ma[x-1][y]=1;
					x-=1;
				} 
				else if(xia==1){
					ma[x+1][y]=1;
					x+=1;
				}
			}
			if(c=='R'){
				if(you==1){
					ma[x+1][y]=1;
					x+=1;
					xia=1;
					zuo=you=shang=0;
				}
				else if(zuo==1){
					ma[x-1][y]=1;
					x-=1;
					shang=1;
					zuo=you=xia=0;
				}
				else if(shang==1){
					ma[x][y+1]=1;
					y+=1;
					you=1;
					shang=zuo=xia=0;
				} 
				else if(xia==1){
					ma[x][y-1]=1;
					y-=1;
					zuo=1;
					shang=xia=you=0;
				}
			}			
			if(c=='L'){
				if(you==1){
					ma[x-1][y]=1;
					x-=1;
					shang=1;
					zuo=you=xia=0;
				}
				else if(zuo==1){
					ma[x+1][y]=1;
					x+=1;
					xia=1;
					zuo=you=shang=0;
				}
				else if(shang==1){
					ma[x][y-1]=1;
					y-=1;
					zuo=1;
					shang=you=xia=0;
				} 
				else if(xia==1){
					ma[x][y+1]=1;
					y+=1;
					you=1;
					shang=xia=zuo=0;
				}
			}
			if(c=='B'){
				if(you==1){
					ma[x][y-1]=1;
					y-=1;
					zuo=1;
					shang=you=xia=0;
				}
				else if(zuo==1){
					ma[x][y+1]=1;
					y+=1;
					you=1;
					zuo=shang=xia=0;
				}
				else if(shang==1){
					ma[x+1][y]=1;
					x+=1;
					xia=1;
					shang=zuo=you=0;
				} 
				else if(xia==1){
					ma[x-1][y]=1;
					x-=1;
					shang=1;
					zuo=xia=you=0;
				}
			}
		//cout<<c<<" "<<shang<<" "<<xia<<" "<<zuo<<" "<<you<<endl;
		//cout<<x<<" "<<y<<endl;
		//system("pause");
		}
		int minxx=1000,minyy=1000;
		int maxx=0,maxy=0;
		for(int i=0;i<400;i++){
			for(int j=0;j<400;j++){
				if(ma[i][j]==1){
					if(i<minxx) minxx=i;
					if(i>maxx) maxx=i;
					if(j<minyy) minyy=j;
					if(j>maxy) maxy=j;
				} 
			}
		}
		
		cout<<maxx-minxx+3<<" "<<maxy+2<<endl;
		for(int i=0;i<=maxy+1;i++) printf("#");
		printf("\n");
		for(int i=minxx;i<=maxx;i++){
			for(int j=0;j<=maxy+1;j++){
				if(ma[i][j]==1){
					printf(".");
				}
				else printf("#");
			}
			printf("\n");
		}
		for(int i=0;i<=maxy+1;i++) printf("#");
		printf("\n");
	}
	return 0;
}

欢迎大家加入 早起学习群,一起学习一起进步!(群号:642179511)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值