A9066 | Shaass and Painter Robot
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of $n·m$ square tiles forming a $n×m$ rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color.
Shaass wants to use a painter robot to color the tiles. In the beginning the robot is standing in a border tile $(x_{s},y_{s})$ facing a diagonal direction (i.e. upper-left, upper-right, down-left or down-right). As the robot walks in the kitchen he paints every tile he passes even if it's painted before. Painting each tile consumes one unit of black paint. If at any moment the robot hits a wall of the kitchen he changes his direction according the reflection rules. Note that a tile gets painted when the robot enters the tile from another tile, in other words changing direction in the same tile doesn't lead to any painting. The first tile the robot is standing on, is also painted.
The robot stops painting the first moment the floor is checkered. Given the dimensions of the kitchen and the position of the robot, find out the amount of paint the robot consumes before it stops painting the floor.
Let's consider an examples depicted below.
If the robot starts at tile number 1 (the tile $(1,1)$ ) of the left grid heading to down-right it'll pass tiles 1354236 and consumes 7 units of black paint on his way until he stops at tile number 6. But if it starts at tile number 1 in the right grid heading to down-right it will get stuck in a loop painting tiles 1, 2, and 3.
Shaass wants to use a painter robot to color the tiles. In the beginning the robot is standing in a border tile $(x_{s},y_{s})$ facing a diagonal direction (i.e. upper-left, upper-right, down-left or down-right). As the robot walks in the kitchen he paints every tile he passes even if it's painted before. Painting each tile consumes one unit of black paint. If at any moment the robot hits a wall of the kitchen he changes his direction according the reflection rules. Note that a tile gets painted when the robot enters the tile from another tile, in other words changing direction in the same tile doesn't lead to any painting. The first tile the robot is standing on, is also painted.
The robot stops painting the first moment the floor is checkered. Given the dimensions of the kitchen and the position of the robot, find out the amount of paint the robot consumes before it stops painting the floor.
Let's consider an examples depicted below.
If the robot starts at tile number 1 (the tile $(1,1)$ ) of the left grid heading to down-right it'll pass tiles 1354236 and consumes 7 units of black paint on his way until he stops at tile number 6. But if it starts at tile number 1 in the right grid heading to down-right it will get stuck in a loop painting tiles 1, 2, and 3.
输入格式
The first line of the input contains two integers $n$ and $m$ , $(2<=n,m<=10^{5})$ . The second line contains two integers $x_{s}$ and $y_{s}$ $(1<=x_{s}<=n,1<=y_{s}<=m)$ and the direction robot is facing initially. Direction is one of the strings: "UL" (upper-left direction), "UR" (upper-right), "DL" (down-left) or "DR" (down-right).
Note, that record $(x_{s},y_{s})$ denotes the tile that is located at the $x_{s}$ -th row from the top and at the $y_{s}$ -th column from the left of the kitchen.
It's guaranteed that the starting position will be a border tile (a tile with less than four side-adjacent tiles).
Note, that record $(x_{s},y_{s})$ denotes the tile that is located at the $x_{s}$ -th row from the top and at the $y_{s}$ -th column from the left of the kitchen.
It's guaranteed that the starting position will be a border tile (a tile with less than four side-adjacent tiles).
输出格式
Print the amount of paint the robot consumes to obtain a checkered kitchen floor. Or print -1 if it never happens.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
输入输出样例
输入 #1
3 4 1 1 DR
输出 #1
7
输入 #2
3 4 3 3 DR
输出 #2
11
输入 #3
3 3 1 1 DR
输出 #3
-1
输入 #4
3 3 1 2 DL
输出 #4
4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted