http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97343#problem/C
Description
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 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 xk, yk(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.
Sample 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
1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1
Hint
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
QWER REWQ ASDF -> FDSA ZXCV VCXZ
这个题目当时比赛的时候就想清楚只要找旋转的规律就可以了,然后写出旋转x,y,z,x和z太大求余4即可。y求余2即可。明明有想到旋转的时候n和m的大小会颠倒,
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
using namespace std;
//#define DEBUG
struct node
{
__int64 x,y;
}a[100010];
int main()
{
#ifdef DEBUG
freopen("cin.txt", "r", stdin);
freopen("cout.txt", "w", stdout);
#endif
__int64 n,m,x,y,z;
int i,p;
memset(a,0,sizeof(a));
scanf("%I64d %I64d %I64d %I64d %I64d %d",&n,&m,&x,&y,&z,&p);
for (i=1;i<=p;i++)
scanf("%I64d %I64d",&a[i].x,&a[i].y);
x%=4;
while (x--)
{
for (i=1;i<=p;i++)
{
int xx=a[i].x;
int yy=a[i].y;
a[i].x=yy;
a[i].y=n-xx+1;
}
int t=m;
m=n;
n=t;
}
y=y%2;
if (y)
for (i=1;i<=p;i++)
a[i].y=m-a[i].y+1;
z%=4;
while (z--)
{
for (i=1;i<=p;i++)
{
int xx=a[i].x;
int yy=a[i].y;
a[i].y=xx;
a[i].x=m-yy+1;
}
int t=m;
m=n;
n=t;
}
for (i=1;i<=p;i++)
printf("%I64d %I64d\n",a[i].x,a[i].y);
return 0;
}