(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.
![](http://espresso.codeforces.com/95bac64a0b84e174ec7da72bcda6111362b62e77.png)
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
Note
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
题意:很明显就是矩阵旋转。给你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了。。。风吹鸡鸡蛋蛋凉。。。
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.
![](http://espresso.codeforces.com/95bac64a0b84e174ec7da72bcda6111362b62e77.png)
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; }
相关文章推荐
- 反转链表
- (补)第一周 日期结构体
- hdu 1712ACboy needs your help 01背包(分组)
- 将Activity设置成半透明的对话框
- 视图和视图解析器---15.4.7: 输出XML
- oracle 11g 使用物化视图远程增量刷新数据
- 带标签的break和continue语句
- JAVA高新技术——代理
- 微信营销完全手册の订阅号运营
- openglel2.0下载
- java封装类(二)
- java使用jsp servlet来防止csrf 攻击的实现方法
- 视图和视图解析器---15.4.6: PDF
- Sensor、TP、Button & 5250
- git常用命令(二)
- 5种方法解除开机密码
- 2周项目1
- IOS-播放沙盒目录及本地音频文件
- 中文编程命名法
- 忘记Mysql数据库密码