您的位置:首页 > 其它

(CF)C. Inna and Huge Candy Matrix

2014-03-06 19:36 337 查看
C. Inna and Huge Candy Matrix

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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 hasp 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 test(s)

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


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

这个题目当时比赛的时候就想清楚只要找旋转的规律就可以了,然后写出旋转x,y,z,x和z太大求余4即可。y求余2即可。明明有想到旋转的时候n和m的大小会颠倒,后来不知道为什么太烦,嫌麻烦就没写吧。反正没过就睡觉去了。晚上就做了一个关于动物园的噩梦!!!有我最怕的蜘蛛,好大好大,海陆空都可以行走的,还有坐骑佬这个煞笔去吵醒蜘蛛王,结果一直跑一直跑,结果醒来已经10点多钟了,全身都湿了,好了,上午的课都翘了。好吧,言归题目,只要每次x,z旋转的时候加上n和m的变化就可以AC了。。。风吹鸡鸡蛋蛋凉。。。

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: