CF400C.Inna and Huge Candy Matrix

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (x__k, y__k).

The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.

Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

因娜和迪马决定给谢尔盖一个惊喜。他们带来了一个超大的糖果矩阵,这个矩阵甚至对谢尔盖来说都大得惊人!我们从上到下将该巨型矩阵的行编号为 11 到 nn,从左到右将列编号为 11 到 mm。我们将第 ii 行与第 jj 列相交的单元格记作 (i, j)(i,\,j)。正如预期的那样,巨型糖果矩阵中的一些单元格含有糖果。整个矩阵共有 pp 颗糖果:第 kk 颗糖果位于单元格 (xk, yk)(x_k,\,y_k)。

晚餐时间临近,因娜正准备从矩阵中取走她最喜爱的 pp 颗糖果,这时谢尔盖(原因他并未向任何人透露)突然将矩阵顺时针旋转了 xx 次,每次 90∘90^\circ;接着又水平翻转(即沿垂直中线镜像)了 yy 次;最后再逆时针旋转了 zz 次,每次 90∘90^\circ。下图展示了矩阵的这些旋转操作效果:

因娜非常沮丧,但杜马却突然明白了两件事:糖果本身并未受损,而且他还记得在谢尔盖进行这些奇怪操作之前,哪些单元格里放着因娜最喜爱的糖果。请帮助他们找出谢尔盖完成上述变换后,这些糖果在糖果矩阵中的新坐标!

输入格式

The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).

Each of the following p lines contains two integers x__k, y__k (1 ≤ x__k ≤ n; 1 ≤ y__k ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.

输入的第一行包含六个整数 nn、mm、xx、yy、zz、pp(其中 1≤n,m≤1091 \leq n, m \leq 10^9;0≤x,y,z≤1090 \leq x, y, z \leq 10^9;1≤p≤1051 \leq p \leq 10^5)。

接下来的 pp 行,每行包含两个整数 xkx_k、yky_k(1≤xk≤n1 \leq x_k \leq n;1≤yk≤m1 \leq y_k \leq m),表示第 kk 颗糖果的初始坐标。两颗糖果可以位于同一格子中。

输出格式

For each of the p candies, print on a single line its space-separated new coordinates.

对于每颗糖果 pp,请在单独一行中输出其以空格分隔的新坐标。

输入输出样例

  • 输入#1

    3 3 3 1 1 9
    1 1
    1 2
    1 3
    2 1
    2 2
    2 3
    3 1
    3 2
    3 3

    输出#1

    1 3
    1 2
    1 1
    2 3
    2 2
    2 1
    3 3
    3 2
    3 1

说明/提示

Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:

QWER REWQ
ASDF -> FDSA
ZXCV VCXZ

仅为明确说明:水平旋转类似于矩阵的镜像翻转。对于矩阵:

QWER → REWQ
ASDF → FDSA
ZXCV → VCXZ

输入解题思路,AI测评打分。不知道怎么写?

首页