题目链接:

PKU:http://poj.org/problem?

id=3344

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414

Description

Another boring Friday afternoon, Betty the Beetle thinks how to amuse herself. She goes out of her hiding place to take a walk around the living room in Bennett's house. Mr. and Mrs. Bennett are out to the theatre and there is a chessboard on the table!
"The best time to practice my chessboard dance," Betty thinks! She gets so excited that she does not note that there are some pieces left on the board and starts the practice session! She has a script showing her how to move on the chessboard. The script is
a sequence like the following example:

At each instant of time Betty, stands on a square of the chessboard, facing one of the four directions (up, down, left, right) when the board is viewed from the above. Performing a "move n" instruction, she moves n squares forward in her
current direction. If moving n squares goes outside the board, she stays at the last square on the board and does not go out. There are three types of turns: turn right, turn left, and turn back, which change the direction of Betty. Note that turning
does not change the position of Betty.

If Betty faces a chess piece when moving, she pushes that piece, together with all other pieces behind (a tough beetle she is!). This may cause some pieces fall of the edge of the chessboard, but she doesn't care! For example, in the following figure, the
left board shows the initial state and the right board shows the state after performing the script in the above example. Upper-case and lower-case letters indicate the white and black pieces respectively. The arrow shows the position of Betty along with her
direction. Note that during the first move, the black king (r) falls off the right edge of the board!

You are to write a program that reads the initial state of the board as well as the practice dance script, and writes the final state of the board after the practice.

Input

There are multiple test cases in the input. Each test case has two parts: the initial state of the board and the script. The board comes in eight lines of eight characters. The letters r, d, t, a, c, p indicate black pieces, R, D, T, A, C, P indicate the
white pieces and the period (dot) character indicates an empty square. The square from which Betty starts dancing is specified by one of the four characters <, >, ^, and v which also indicates her initial direction (left, right, up, and down respectively).
Note that the input is not necessarily a valid chess game status.

The script comes immediately after the board. It consists of several lines (between 0 and 1000). In each line, there is one instruction in one of the following formats (n is a non-negative integer number):

move n

turn left

turn right

turn back

At the end of each test case, there is a line containing a single # character. The last line of the input contains two dash characters.

Output

The output for each test case should show the state of the board in the same format as the input. Write an empty line in the output after each board.

Sample Input

.....c..
.p..A..t
D..>T.Pr
....aP.P
p.d.C...
.....p.R
........
........
move 2
turn right
move 3
turn left
turn left
move 1
#
--

Sample Output

.....c..
.p..A..t
D.....TP
....a..P
p.d.C^..
.......R
.....P..
.....p..

Source

题意:

模拟推箱子的过程,依照所给的步骤推完后输出终于的棋盘状态!

PS:

注意在推的过程中,不能走出棋盘外,所推的棋子能够出棋盘。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 27;
char mm[maxn][maxn];
struct node
{
int x;
int y;
int dir;
} p;
char dir[4] = {'v','>','^','<'};
//写为下、右、上、左是为了turn back操作
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1}; int vis(int x, int y)
{
if(x<1 || x>8)
return 0;
if(y<1 || y>8)
return 0;
return 1;
}
void DFS(int x, int y)
{
if(mm[x][y]=='.')
{
mm[x][y]=mm[x-dx[p.dir]][y-dy[p.dir]];
mm[x-dx[p.dir]][y-dy[p.dir]]='.';
}
else
{
DFS(x+dx[p.dir],y+dy[p.dir]);
mm[x][y]=mm[x-dx[p.dir]][y-dy[p.dir]];
mm[x-dx[p.dir]][y-dy[p.dir]]='.';
}
}
void Rush()
{
for(int i = 0; i <= 8; i++)
{
//初始化棋盘外的一圈全为'.'
mm[0][i]=mm[i][0]=mm[9][i]=mm[i][9]='.';
}
mm[p.x][p.y] = '.';
if(!vis(p.x+dx[p.dir],p.y+dy[p.dir]))
return ;
DFS(p.x+dx[p.dir],p.y+dy[p.dir]);
p.x += dx[p.dir];
p.y += dy[p.dir];
} int main()
{
char a[maxn], b[maxn];
int step;
while(scanf("%s",mm[1]+1))
{
if(mm[1][1] == '-')
break;
for(int i = 2; i <= 8; i++)
{
scanf("%s",mm[i]+1);
}
for(int i = 1; i <= 8; i++)
{
for(int j = 1; j <= 8; j++)
{
if(mm[i][j] == 'v')
{
p.x = i,p.y = j,p.dir = 0;
}
else if(mm[i][j] == '>')
{
p.x = i,p.y = j,p.dir = 1;
}
else if(mm[i][j] == '^')
{
p.x = i,p.y = j,p.dir = 2;
}
else if(mm[i][j] == '<')
{
p.x = i,p.y = j,p.dir = 3;
}
}
}
while(scanf("%s",a))
{
if(a[0] == '#')
break;
if(a[0] == 't')
{
scanf("%s",b);
if(b[0] == 'l')
p.dir=(p.dir+1)%4;
else if(b[0]=='r')
p.dir=(p.dir+3)%4;
else
p.dir=(p.dir+2)%4;
}
else
{
scanf("%d",&step);
for(int i = 0; i < step; i++)
{
Rush();
}
}
}
mm[p.x][p.y] = dir[p.dir];
for(int i = 1; i <= 8; i++)
{
for(int j = 1; j <= 8; j++)
{
printf("%c",mm[i][j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}

POJ 3344 &amp; HDU 2414 Chessboard Dance(模拟)的更多相关文章

  1. HDU 2414 Chessboard Dance (力模拟)

    主题链接:HDU 2414 Chessboard Dance 意甲冠军:鉴于地图,>,<,^,v的方向,字母相当于是箱子,箱子能够推出边界.人保证不会做出边界.以下输入指令,依照指令走,输 ...

  2. HDU 2414 Chessboard Dance(模拟题,仅此纪念我的堕落)

    题目 模拟题也各种wa,我最近真的堕落了,,,,,智商越来越为负数了!!!!!!!! #include<stdio.h> #include<string.h> #include ...

  3. 【HDOJ】2414 Chessboard Dance

    简单DFS. /* 2414 */ #include <cstdio> #include <cstring> #include <cstdlib> ; ][]; i ...

  4. 洛谷 P2033 Chessboard Dance

    P2033 Chessboard Dance 题目描述 在棋盘上跳舞是件有意思的事情.现在给你一张国际象棋棋盘和棋盘上的一些子以及你的初始位置和方向.求按一定操作后,棋盘的状态. 操作有四种,描述如下 ...

  5. POJ 3488 &amp; HDU 1915 Arne Saknussemm(模拟)

    题目链接: POJ:http://poj.org/problem? id=3488 HDU:pid=1915">http://acm.hdu.edu.cn/showproblem.ph ...

  6. HDU 5510---Bazinga(指针模拟)

    题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...

  7. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

  8. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  9. HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

    扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...

随机推荐

  1. ACM_圆的面积

    圆的面积 Time Limit: 2000/1000ms (Java/Others) Problem Description: AB是圆O的一条直径,CD.EF是两条垂直于AB的弦,并且以CD为直径的 ...

  2. 1、Web MVC简介

  3. 350 Intersection of Two Arrays II 两个数组的交集 II

    给定两个数组,写一个方法来计算它们的交集.例如:给定 nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回 [2, 2].注意:       输出结果中每个元素出现的次数, ...

  4. [Windows Server 2003] 还原SQL Server数据库

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:SQL Ser ...

  5. VC使用CryptoAPI计算MD5

    // md5.h #include <tchar.h> #include <wincrypt.h> // 计算Hash,成功返回0,失败返回GetLastError() // ...

  6. CNN结构:色彩空间建模-色彩空间分析

    原文: 色彩空间基础 好一个NB的知乎专栏:色彩空间基础 第一章:色彩空间基础 关于色彩分析,引出了专门的数学基础.整个过程给出了完备的数学阐述,虽然没有试验数据,论述的相当精彩. 摘抄出一段:  上 ...

  7. 【sqli-labs】 less45 POST -Error based -String -Stacked Blind(POST型基于盲注的堆叠字符型注入)

    和Less44一个名字 测试一下,发现是')闭合的 login_user=&login_password=1') or sleep(0.1)# 那就是没有错误显示的less42 login_u ...

  8. listcontrol 加combobox

    之前写过一篇(list Control实现单元格编辑)文章,那篇文章不是很完善执行的时候有时会出错,这篇文章经过完善后还加入了Combo Box功能! 这里我就只是晒一下我的代码; 头文件: // L ...

  9. linux中快速查找文件

    在使用linux时,经常需要进行文件查找.其中查找的命令主要有find和grep.两个命令是有区的. 区别:(1)find命令是根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空,访 ...

  10. golang bytes 包

    类型 []byte 的切片十分常见,Go 语言有一个 bytes 包专门用来解决这种类型的操作方法. bytes 包和字符串包十分类似.而且它还包含一个十分有用的类型 Buffer: import & ...