301458: CF274E. Mirror Room

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Mirror Room

题意翻译

有一个n*m的格子图,其中有一些是黑色的,另一些为白色。 从某个白色格子的中心点向左上(NW),左下(SW),右上(NE),右下(SE)四个方向中的一个发出一束光线,若光线碰到黑色格子或者墙壁(即边界)会反射。反射情况如图所示: ![](https://cdn.luogu.org/upload/vjudge_pic/CF274E/b39481b94e1363a19d54d5d4b6abfa8c6904b83d.png) 我们不难发现,光线能穿过的格子总数是可以算出的。假如光线经过了某个格子的中心,则称光线经过了这个格子。求光线经过的格子总数。 由于答案可能很大,请使用long long的C++选手注意:请勿使用%lld,推荐cout或者%I64d

题目描述

Imagine an $ n×m $ grid with some blocked cells. The top left cell in the grid has coordinates $ (1,1) $ and the bottom right cell has coordinates $ (n,m) $ . There are $ k $ blocked cells in the grid and others are empty. You flash a laser beam from the center of an empty cell $ (x_{s},y_{s}) $ in one of the diagonal directions (i.e. north-east, north-west, south-east or south-west). If the beam hits a blocked cell or the border of the grid it will reflect. The behavior of the beam reflection in different situations is depicted in the figure below. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF274E/b39481b94e1363a19d54d5d4b6abfa8c6904b83d.png)After a while the beam enters an infinite cycle. Count the number of empty cells that the beam goes through at least once. We consider that the beam goes through cell if it goes through its center.

输入输出格式

输入格式


The first line of the input contains three integers $ n $ , $ m $ and $ k $ $ (1<=n,m<=10^{5},0<=k<=10^{5}) $ . Each of the next $ k $ lines contains two integers $ x_{i} $ and $ y_{i} $ $ (1<=x_{i}<=n,1<=y_{i}<=m) $ indicating the position of the $ i $ -th blocked cell. The last line contains $ x_{s} $ , $ y_{s} $ $ (1<=x_{s}<=n,1<=y_{s}<=m) $ and the flash direction which is equal to "NE", "NW", "SE" or "SW". These strings denote directions $ (-1,1) $ , $ (-1,-1) $ , $ (1,1) $ , $ (1,-1) $ . It's guaranteed that no two blocked cells have the same coordinates.

输出格式


In the only line of the output print the number of empty cells that the beam goes through at least once. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入输出样例

输入样例 #1

3 3 0
1 2 SW

输出样例 #1

6

输入样例 #2

7 5 3
3 3
4 3
5 3
2 1 SE

输出样例 #2

14

Input

题意翻译

有一个n*m的格子图,其中有一些是黑色的,另一些为白色。 从某个白色格子的中心点向左上(NW),左下(SW),右上(NE),右下(SE)四个方向中的一个发出一束光线,若光线碰到黑色格子或者墙壁(即边界)会反射。反射情况如图所示: ![](https://cdn.luogu.org/upload/vjudge_pic/CF274E/b39481b94e1363a19d54d5d4b6abfa8c6904b83d.png) 我们不难发现,光线能穿过的格子总数是可以算出的。假如光线经过了某个格子的中心,则称光线经过了这个格子。求光线经过的格子总数。 由于答案可能很大,请使用long long的C++选手注意:请勿使用%lld,推荐cout或者%I64d

加入题单

上一题 下一题 算法标签: