P2033 Chessboard Dance
题目描述
在棋盘上跳舞是件有意思的事情。现在给你一张国际象棋棋盘和棋盘上的一些子以及你的初始位置和方向。求按一定操作后,棋盘的状态。
操作有四种,描述如下:
move n n是非负整数,表示你按目前所在方向前进n步,如果即将走出棋盘,则停止。如果面前有棋子,则将其向前推一步。
turn left 向左转90度
turn right 向右转90度
turn back 向后转
输入格式
输入前8行,每行8个字符,给出棋盘状态。“.”表示该格为空,字母表示棋子,不同字母表示不同的棋子。你所在位置用“^”、“<”、“>”、“v”四个字母中一个表示,分别表示你的方向上、左、右、下。
接下来有若干行,每行一个操作。以“#”结束。操作数不超过1000个。
输出格式
输出8行,每行8个字符,表示经过一系列操作后棋盘和你的状态。表示方法同输入。
输入输出样例
输入
......bA
.....^..
........
........
........
........
........
........
move 2
turn right
move 1
#
输出
......>b
........
........
........
........
........
........
........
分析
如果前面是空地,直接向前走。
如果前面是字符,先遍历字符前面的点,如果遍历到一个空地再推
如果当前点到达了边界则break。
真就直接暴力模拟
多个棋子可以一起推
程序
#include <bits/stdc++.h> using namespace std; char s[10001][10001];
char situtation[4] = {'^','v','<','>'};
int direction = 0 , x , y;
int direction_back[5] = {0 , 2 , 1 , 4 , 3};
int direction_right[5] = {0 , 4 , 3 , 1 , 2};
int direction_left[5] = {0 , 3 , 4 , 2 , 1}; void Go_Up(int k)
{
int x_next = x;
int y_next = y;
for(int i = x - 1; i >= 1; i--)
{
if(x_next == 1)
break;
if(!k)
break;
if(s[i][y] == '.')
{
x_next--;
k--;
continue;
}
if(s[i][y] != '.')
{
int flag = i;
for(int j = i; j >= 1; j--)
if(s[j][y] == '.' || j == 1)
{
flag = j;
break;
}
for(int j = flag; j <= i; j++)
s[j][y] =s [j + 1][y];
x_next--;
k--;
}
}
x = x_next;
}
void Go_Down(int k)
{
int x_next = x;
int y_next = y;
for(int i = x + 1; i <= 8; i++)
{
if(x_next == 8)
break;
if(!k)
break;
if(s[i][y] == '.')
{
x_next++;
k--;
continue;
}
if(s[i][y] != '.')
{
int flag = i;
for(int j = i; j <= 8; j++)
if(s[j][y] == '.' || j == 8)
{
flag = j;
break;
}
for(int j = flag; j >= i; j--)
s[j][y] = s[j - 1][y];
x_next++;
k--;
}
}
x = x_next;
}
void Go_Left(int k)
{
int y_next = y;
for(int i = y - 1; i >= 1; i--)
{
if(y_next == 1)
break;
if(k == 0)
break;
if(s[x][i] == '.')
{
y_next--;
k--;
continue;
}
if(s[x][i] != '.')
{
int flag = i;
for(int j = i; j >= 1; j--)
{
if(s[x][j] == '.'||j == 1)
{
flag = j;
break;
} }
for(int j = flag; j <= i; j++)
s[x][j] = s[x][j + 1];
y_next--;
k--;
}
}
y = y_next;
}
void Go_Right(int k)
{
int y_next = y;
for(int i = y + 1; i <= 8; i++)
{
if(y_next == 8)
break;
if(!k)
break;
if(s[x][i] == '.')
{
y_next++;
k--;
continue;
}
if(s[x][i] != '.')
{
int flag = i;
for(int j = i; j <= 8; j++)
{
if(s[x][j] == '.' || j == 8)
{
flag = j;
break;
} }
for(int j = flag; j >= i; j--)
s[x][j] = s[x][j - 1];
y_next++;
k--;
}
}
y = y_next;
}
int main()
{
ios::sync_with_stdio(false);
for(int i = 1; i <= 8; i++)
for(int j = 1; j <= 8; j++)
{
cin >> s[i][j];
if(s[i][j] == '^')
{
direction=1;
s[i][j] = '.';
x = i;
y = j;
}
if(s[i][j] == 'v')
{
direction = 2;
x = i;
y = j;
s[i][j] = '.';
}
if(s[i][j] == '<')
{
x = i;
y = j;
s[i][j] = '.';
direction = 3;
}
if(s[i][j] == '>')
{
x = i;
y = j;
s[i][j] = '.';
direction = 4;
}
}
string a,b;
int c;
int t = 0;
while(1)
{
cin >> a;
if(a == "#")
break;
else
if(a == "turn")
{
cin >> b;
if(b == "right")
direction = direction_right[direction];
else
if(b == "left")
direction = direction_left[direction];
else
if(b == "back")
direction = direction_back[direction];
}
else
if(a == "move")
{
cin >> c;
if(direction == 1)
Go_Up(c);
else
if(direction == 2)
Go_Down(c);
else
if(direction == 3)
Go_Left(c);
else
if(direction == 4)
Go_Right(c);
}
}
for(int i = 1; i <= 8; i++)
{
for(int j = 1; j <= 8; j++)
{
if(x == i && y == j)
cout << situtation[direction - 1];
else
cout << s[i][j];
}
cout << endl;
}
return 0;
}
P2033 Chessboard Dance的更多相关文章
- 洛谷 P2033 Chessboard Dance
P2033 Chessboard Dance 题目描述 在棋盘上跳舞是件有意思的事情.现在给你一张国际象棋棋盘和棋盘上的一些子以及你的初始位置和方向.求按一定操作后,棋盘的状态. 操作有四种,描述如下 ...
- HDU 2414 Chessboard Dance (力模拟)
主题链接:HDU 2414 Chessboard Dance 意甲冠军:鉴于地图,>,<,^,v的方向,字母相当于是箱子,箱子能够推出边界.人保证不会做出边界.以下输入指令,依照指令走,输 ...
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...
- 【HDOJ】2414 Chessboard Dance
简单DFS. /* 2414 */ #include <cstdio> #include <cstring> #include <cstdlib> ; ][]; i ...
- HDU 2414 Chessboard Dance(模拟题,仅此纪念我的堕落)
题目 模拟题也各种wa,我最近真的堕落了,,,,,智商越来越为负数了!!!!!!!! #include<stdio.h> #include<string.h> #include ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- CodeForces445A DZY Loves Chessboard
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- pycharm2019
812LFWMRSH-eyJsaWNlbnNlSWQiOiI4MTJMRldNUlNIIiwibGljZW5zZWVOYW1lIjoi5q2j54mIIOaOiOadgyIsImFzc2lnbmVlT ...
- HTTP自定义Header-(SOCKET-TCP)
HTTP自定义Header-TCP 前几天弄一些东西,需要在发送http请求的时候自定义http头,找了几个库用着很不爽.有的把Cookie直接干掉了,还自己在头里加了版权,最后终于忍不了了.在网 ...
- 指定的服务已标记为删除 寒江孤钓<<windows 内核安全编程>> 学习笔记
运行cmd:"sc delete first" 删除我们的服务之后, 再次创建这个服务的时候出现 "指定的服务已标记为删除"的错误, 原因是我们删除服务之前没有 ...
- 在Visual Studio 中使用git——文件管理-上(四)
在Visual Studio 中使用git--什么是Git(一) 在Visual Studio 中使用git--给Visual Studio安装 git插件(二) 在Visual Studio 中使用 ...
- StreamReader & StreamWriter
这节讲StreamReader & StreamWriter,这两个类用于操作字符或者字符串,它将流的操作封装在了底层,相对来说用法比较简单,但是它不支持Seek()方法. 先看一下代码: F ...
- PostgreSQL条件表达式
条件表达式在日常工作中很多场景都会用到,比如某个字段为空,取另外一个字段:某个值大于多少,取什么字段,小于多少取什么字段等等.那么下面来简单的学习下PostgreSQL有那些条件表达式. 1.CA ...
- docker-compose如何动态配置springboot项目的application.yml的配置
假如我们再springboot的工程中有配置文件 方式1: application.properties里面存在环境变量: #配置数据库链接 spring.datasource.url = jdbc: ...
- Apache Hudi集成Spark SQL抢先体验
Apache Hudi集成Spark SQL抢先体验 1. 摘要 社区小伙伴一直期待的Hudi整合Spark SQL的PR正在积极Review中并已经快接近尾声,Hudi集成Spark SQL预计会在 ...
- Installing SFTP/SSH Server on Windows using OpenSSH
Installing SFTP/SSH Server 1. On Windows 10 version 1803 and newer In Settings app, go to Apps > ...
- ScreenToGif: 屏幕录制神器
ScreenToGif:一款小众但很好用的屏幕录制神器 牛人干货 2020-01-07 00:23:08 今天干货君给大家介绍一款电脑屏幕录制神器-ScreenToGif . ScreenToGif ...