您的位置:首页 > 其它

C - Inna and Huge Candy Matrix

2015-10-31 15:22 453 查看
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97343#problem/C

C - Inna and Huge Candy Matrix
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
400C

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

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


Hint

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

QWER      REWQ
ASDF  ->  FDSA
ZXCV      VCXZ


题意:很明显就是矩阵旋转。给你n*m个矩阵,每个坐标(xi,yi)代表一个糖果吧。一个人将他向右90度旋转x次,然后平行转换y次,再向左90度旋转z次,问p个坐标旋转后的位置。

这个题目当时比赛的时候就想清楚只要找旋转的规律就可以了,然后写出旋转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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: