cf(旋转矩阵)
2015-10-31 14:36
316 查看
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
Output
Hint
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
题意是顺时针旋转矩阵x次,然后将矩阵做镜子一样的变换y次然后逆时针旋转z次之后求点对应的坐标。
需要我们找到旋转和翻转之后的坐标关系。
还有要注意的是旋转90度之后的m和n会对应的变换!而且变换了之后还不可以影响下一组数据,卡这两点真实卡死我了。。。。
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
题意是顺时针旋转矩阵x次,然后将矩阵做镜子一样的变换y次然后逆时针旋转z次之后求点对应的坐标。
需要我们找到旋转和翻转之后的坐标关系。
还有要注意的是旋转90度之后的m和n会对应的变换!而且变换了之后还不可以影响下一组数据,卡这两点真实卡死我了。。。。
#include <iostream> #include <stdio.h> #include <math.h> #include<algorithm> using namespace std; int n, m, x, y, z, p; int hx,hy; void hh() { int a1=m,a2=n; int dx=hx-1,dy=hy-1; int xx=x%4,yy=y%2,zz=z%4; if(xx==1) hx=1+dy,hy=n-dx,swap(m,n); else if(xx==2) hx=n-dx,hy=m-dy; else if(xx==3) hx=m-dy,hy=1+dx,swap(m,n); dx=hx-1,dy=hy-1; if(yy==1) hx=1+dx,hy=m-dy; dx=hx-1,dy=hy-1; if(zz==1) hx=m-dy,hy=1+dx,swap(m,n); else if(zz==2) hx=n-dx,hy=m-dy; else if(zz==3) hx=1+dy,hy=n-dx,swap(m,n); m=a1,n=a2; cout<<hx<<' '<<hy<<endl; } int main() { cin>>n>>m>>x>>y>>z>>p; for(int i=0;i<p;i++) { scanf("%d%d",&hx,&hy); hh(); } return 0; }
相关文章推荐
- Spring4:JDBC
- 新浪微博---首页技术点二.轮播图的实现
- java数组转json
- hdu 2121
- 设置maven的编译级别
- 杭电5500排书
- css3中transform和transition的用法
- Hadoop 2.6.0集群搭建
- codeforces 416E President's Path floyd+D(递)P(推)
- #坑2# 强制旋转应用当前屏幕
- poj1664递归放苹果
- Declaring an explicit serialVersionUID
- 8,6,5,4,1逆序排放,为什么会出现-858993460 ,4,5,6,8?
- btrace
- 第五章 单表查询,聚合函数查询,连接查询,子查询,合并查询结果,为表和字段取别名
- SQLite数据库收缩研究及学习认识
- UG NX 二次开发 转档图片
- nyoj 75 日期问题
- VS2013使用过期的问题
- poj 3281 Dining 最大流