codeforces400C

Inna and Huge Candy Matrix

 CodeForces - 400C 

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 (xk, yk).

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!

Input

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

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

Output

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

Examples

Input
3 3 3 1 1 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1

Note

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


QWER REWQ
ASDF -> FDSA
ZXCV VCXZ

sol:题意简单清晰,只要膜过以后暴力模拟即可
/*
题目大意:给出n,m,x,y,z和p,表示在一个n*m的矩阵上有p块糖果,
给出p块糖果的坐标,然后将整个矩阵顺时针旋转x次,镜像翻转y次,
逆时针旋转z次,然后按照顺序输出操作完后糖果的坐标.
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0;
    bool f=0;
    char ch=' ';
    while(!isdigit(ch))
    {
        f|=(ch=='-'); ch=getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
    }
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0)
    {
        putchar('-'); x=-x;
    }
    if(x<10)
    {
        putchar(x+'0'); return;
    }
    write(x/10);
    putchar((x%10)+'0');
    return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=100005;
int n,m,X,Y,Z,cnt;
struct Point
{
    int x,y;
}P[N];
inline void SSZ()
{
    int i;
    for(i=1;i<=cnt;i++)
    {
        int xx=P[i].x,yy=P[i].y;
        P[i].x=yy; P[i].y=n-xx+1;
    }
    swap(n,m);
}
inline void JX()
{
    int i;
    for(i=1;i<=cnt;i++) P[i].y=m-P[i].y+1;
}
inline void NSZ()
{
    int i;
    for(i=1;i<=cnt;i++)
    {
        int xx=P[i].x,yy=P[i].y;
        P[i].x=m-yy+1; P[i].y=xx;
    }
    swap(n,m);
}
int main()
{
    int i;
    R(n); R(m); R(X); R(Y); R(Z); R(cnt);
    for(i=1;i<=cnt;i++) {R(P[i].x); R(P[i].y);}
    X%=4; Y%=2; Z%=4;
    for(i=1;i<=X;i++) SSZ();
    for(i=1;i<=Y;i++) JX();
    for(i=1;i<=Z;i++) NSZ();
    for(i=1;i<=cnt;i++) W(P[i].x),Wl(P[i].y);
    return 0;
}
/*
Input
3 3 3 1 1 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1
*/
View Code

 

 

转载于:https://www.cnblogs.com/gaojunonly1/p/11148324.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值