C. Inna and Huge Candy Matrix(cf)
2014-03-07 15:55
417 查看
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
output
题意:吃糖果,有n*m的数组,里面有糖果,输入p行,每一个有两个数,表示坐标,然后顺时针旋转x次,水平旋转y次,逆时针旋转z次,输出数组的坐标
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
题意:吃糖果,有n*m的数组,里面有糖果,输入p行,每一个有两个数,表示坐标,然后顺时针旋转x次,水平旋转y次,逆时针旋转z次,输出数组的坐标
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int n,m,x,y,z,p; struct node { int xi; int yj; }Node[100005]; void swap(int &a,int &b) { int t=a; a=b; b=t; } void cw() { for(int i=0;i<p;i++) { int r=Node[i].yj; int l=n+1-Node[i].xi; Node[i].xi=r; Node[i].yj=l; } swap(n,m); } void hr() { for(int i=0;i<p;i++) Node[i].yj=m+1-Node[i].yj; } void ccw() { for(int i=0;i<p;i++) { int r=m+1-Node[i].yj; int l=Node[i].xi; Node[i].xi=r; Node[i].yj=l; } swap(n,m); } int main() { cin>>n>>m>>x>>y>>z>>p; for(int i=0;i<p;i++) { cin>>Node[i].xi>>Node[i].yj; } x%=4; y%=2; z%=4; for(int i=0;i<x;i++) cw(); for(int i=0;i<y;i++) hr(); for(int i=0;i<z;i++) ccw(); for(int i=0;i<p;i++) cout<<Node[i].xi<<" "<<Node[i].yj<<endl; return 0; }
相关文章推荐
- CF 400C - Inna and Huge Candy Matrix
- (CF)C. Inna and Huge Candy Matrix
- codeforces 400 C Inna and Huge Candy Matrix【模拟】
- codeforces 400C Inna and Huge Candy Matrix
- codeforces 400C - Inna and Huge Candy Matrix(耐心找规律,细节还是要注意的)
- Codeforces 400B Inna and Huge Candy Matrix(模拟)
- codeforces C. Inna and Huge Candy Matrix
- codeforces 400C - Inna and Huge Candy Matrix
- Codeforces 400C Inna and Huge Candy Matrix 【模拟】
- Codeforces 400C Inna and Huge Candy Matrix
- Codeforces 400 C. Inna and Huge Candy Matrix
- Codeforces 400C Inna and Huge Candy Matrix(模拟)
- Codeforces 400 C. Inna and Huge Candy Matrix【 Codeforces Round #234 (Div. 2)】
- C - Inna and Huge Candy Matrix
- codeforces round #234B(DIV2) C Inna and Huge Candy Matrix
- codeforces Inna and Huge Candy Matrix
- (CF)B. Inna and New Matrix of Candies
- cf B Inna and Candy Boxes
- CF 390C:Inna and Candy Boxes
- CF 390D:Inna and Sweet Matrix