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=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,X,Y,Z,cnt;
struct Point
{
int x,y;
}P[N];
inline void SSZ()
{
int i;
for(i=;i<=cnt;i++)
{
int xx=P[i].x,yy=P[i].y;
P[i].x=yy; P[i].y=n-xx+;
}
swap(n,m);
}
inline void JX()
{
int i;
for(i=;i<=cnt;i++) P[i].y=m-P[i].y+;
}
inline void NSZ()
{
int i;
for(i=;i<=cnt;i++)
{
int xx=P[i].x,yy=P[i].y;
P[i].x=m-yy+; 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=;i<=cnt;i++) {R(P[i].x); R(P[i].y);}
X%=; Y%=; Z%=;
for(i=;i<=X;i++) SSZ();
for(i=;i<=Y;i++) JX();
for(i=;i<=Z;i++) NSZ();
for(i=;i<=cnt;i++) W(P[i].x),Wl(P[i].y);
return ;
}
/*
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
*/
 

codeforces400C的更多相关文章

随机推荐

  1. C#进阶之WebAPI(一)

    最近出去面试,被问到关于WebAPI的知识,因为项目中没有单独写过WebAPI,使用的时候是和mvc结合在一起使用的,所以,在我的印象中WebAPI和mvc是差不多的,这种答案当然不能让人满意了,于是 ...

  2. [转载]为什么用Java开发桌面程序的比较少

    这个是本人这几天用javafx开发桌面程序时候想到的,因为虽然javafx比C#之类的确实坑多不少,但是习惯了之后也还行,而且它的一次编译.各处使用真的深得我心.但为什么不流行呢: 作者:bell 来 ...

  3. vue之scoped穿透

    vue之scoped穿透 问题:在页面中,需要了第三方插件的样式,又不想取消scoped,防止造成样式污染 方法:>>> 代码: #tab >>> .ivu-tab ...

  4. 小程序setData方法使用总结

    做了一下小程序setData使用方法总结,如有错误,请不吝指出,Thanks♪(・ω・)ノ  //示例data: data:{ user:'young', obj:{ name:'蓝色蒲公英', ag ...

  5. 常见DML语句汇总

    DML操作是指对数据中表记录的操作,主要包括表记录的插入(insert).更新(update).删除(delete)和查询(select),是开发人员日常使用最频繁的操作,下面依次对它们进行介绍. ( ...

  6. EF Code First 数据迁移操作

    打开执行命令窗体 1.EF Code First创建数据库 PM> Install-Package EntityFramework 2.EF Code First数据库迁移 2.1.生成数据库 ...

  7. C#字符串和16进制字符串之间的转换

    将字符串编码成 16进制 字符串表示: using System;using System.Collections.Generic;using System.Linq;using System.Tex ...

  8. C# 获取 oracle 存储过程输出参数值

    public bool QueueToRegister(string appointsId, string enrolDoctor) { using (OleDbConnection conn = n ...

  9. 【XDOJ】小W的塔防

    原题: 小W在成功拿到iPhone后,下载了一个塔防游戏.游戏的目标是阻止僵尸穿过地图. 地图可以看作一条长度为n的线段,这条线段被划分为n条单位长度的小线段.僵尸需要花费t秒才能通过一条小线段.在每 ...

  10. usb发送字节