codeforces Inna and Huge Candy Matrix
2015-10-30 21:04
471 查看
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的矩阵,其中有p个格子里边有糖果,知道这p个格子现在的位置,现在要将这个n*m的矩阵顺时针旋转x次,水平翻转y次,逆时针旋转z次,最后输出原来的p个有糖果的格子现在的坐标;
找出规律:
顺时针旋转四次回位
水平翻转二次
逆时针旋转四次
顺时针旋转一次(x,y)-(y,n+1-x)
水平翻转一次(x,y)-(x,m+1-y)
逆时针旋转一次(x,y)-(m+1-y,x)
注意顺逆时针旋转是n,m在变;
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的矩阵,其中有p个格子里边有糖果,知道这p个格子现在的位置,现在要将这个n*m的矩阵顺时针旋转x次,水平翻转y次,逆时针旋转z次,最后输出原来的p个有糖果的格子现在的坐标;
找出规律:
顺时针旋转四次回位
水平翻转二次
逆时针旋转四次
顺时针旋转一次(x,y)-(y,n+1-x)
水平翻转一次(x,y)-(x,m+1-y)
逆时针旋转一次(x,y)-(m+1-y,x)
注意顺逆时针旋转是n,m在变;
[code]#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; //顺时针旋转一次(x,y)-(y,n+1-x) //水平翻转一次(x,y)-(x,m+1-y) //逆时针旋转一次(x,y)-(m+1-y,x) int main() { int n,m,x,y,z,p; cin>>n>>m>>x>>y>>z>>p; int a,b; x=x%4; y=y%2; z=z%4; for(int i=0; i<p; i++) { int m1=m,n1=n; cin>>a>>b; if(x!=0) for(int j=0; j<x; j++) { int tmp=a; a=b; b=n1+1-tmp; tmp=m1; m1=n1; n1=tmp; } if(y==1) b=(m1+1-b); if(z!=0) for(int j=0; j<z; j++) { int tmp=a; a=m1+1-b; b=tmp; tmp=m1; m1=n1; n1=tmp; } cout<<a<<" "<<b<<endl; } return 0; }
相关文章推荐
- cnblogs技术知识共享
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- MFC CTreeCtr 鼠标扫过显示备注信息,双击某一节点弹出对话框
- JavaScript 匿名函数(anonymous function)与闭包(closure)
- 151030
- 矩形覆盖
- HDU 3374 String Problem (最小表示法)
- HANA学院(3)-Create(创建)
- java.lang.UnsatisfiedLinkError,findLibrary returned null的一种可能的解决方式
- UILabel学习总结
- Hibernate运行机制分析
- 父母不欠你什么
- BZOJ1970 Code矿藏编码
- ARC 学习笔记(一)
- FCKeditor在线文本编辑器
- 浅谈vo pojo javabean dto
- Activiti工作流(6):流程实例、任务的执行
- javascript深入理解js闭包
- 机器学习常见算法分类汇总
- C#——委托和事件