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. DisableThreadLibraryCalls与DLLMain死锁

    1.首先写个简单的DLL,用来验证 BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserve ...

  2. 用Fiddler模拟低速网络环境【转】

    原文链接:http://caibaojian.com/fiddler.html 我们为什么要限速 限速对于web前端研发是非常重要的,由于开发者的机器一般配置都很高,并且是在localhost下来调试 ...

  3. JS基础_质数练习的改进,提高程序执行效率

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. maven:无效的目标发行版:11

    maven:无效的目标发行版:11 我之前在博客里是不记录bug和error的处理的,昨天听了一个资深程序员的视频,决定要改习惯了,记录一些自己平时遇到的问题 这个是我在mvn clean insta ...

  5. vue中keep-alive路由缓存

    <keep-alive> <component v-bind:is="view"></component> </keep-alive> ...

  6. centos7andcentos6初始化脚本

    #!/bin/bash # get OS verison RELEASEVER=$(rpm -q --qf "%{Version}" $(rpm -q --whatprovides ...

  7. 并发编程J.U.C之AQS剖析

    一.j.u.c简介 在说主题AQS之前,我们有必要先来说一下J.U.C 顾名思义J.U.C就是java.util.concurrent,java并发工具包.由我们的并发大师老爷子Doug Lea亲自操 ...

  8. 搜索框+ 定时器+Bug解决

    定时器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  9. 微软宣布加入机密计算联盟,与谷歌和BAT 等巨头联手保护数据安全

    联盟创始成员还包括阿里巴巴.Arm.百度.谷歌.IBM.英特尔.红帽.瑞士电信和腾讯等科技公司,它提供了一个让行业聚集起来的机会,以促进使用机密计算来更好地保护数据. 建立机密计算联盟的需求源于这样一 ...

  10. servlet遇到的问题

    1 创建web项目没有xml自动生成 2  servlet 忽然报奇怪500错误  出现的BUG原因 JAVA bean没有设置  自动导入了其他User包