C - Inna and Huge Candy Matrix
2015-10-31 15:22
453 查看
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97343#problem/C
C - Inna and Huge Candy Matrix
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
400C
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:
题意:很明显就是矩阵旋转。给你n*m个矩阵,每个坐标(xi,yi)代表一个糖果吧。一个人将他向右90度旋转x次,然后平行转换y次,再向左90度旋转z次,问p个坐标旋转后的位置。
这个题目当时比赛的时候就想清楚只要找旋转的规律就可以了,然后写出旋转x,y,z,x和z太大求余4即可。y求余2即可。明明有想到旋转的时候n和m的大小会颠倒,
C - Inna and Huge Candy Matrix
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
400C
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个矩阵,每个坐标(xi,yi)代表一个糖果吧。一个人将他向右90度旋转x次,然后平行转换y次,再向左90度旋转z次,问p个坐标旋转后的位置。
这个题目当时比赛的时候就想清楚只要找旋转的规律就可以了,然后写出旋转x,y,z,x和z太大求余4即可。y求余2即可。明明有想到旋转的时候n和m的大小会颠倒,
#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; }
相关文章推荐
- Android 开发基础系列——程序崩溃之Unable to instantiate activity ComponentInfo
- ufldl.PCA-2D实现
- S3C2440裸机之S3C2440GPIO
- POJ 百炼 保研机试 2743:字符串判等
- 博客引入漂亮字体二三事
- selenium2截图ScreenShot的使用
- SpringMVC中为什么已经作废了session, 在另一个jsp中仍然能取到session中的值?
- C# WinForm程序App.Config数据库连接配置文件的使用过程
- FaceNet: A Unified Embedding for Face Recognition and Clustering
- POJ 百炼 保研机试 2976:All in All
- 与ORA-28000: the account is locked-的解决办法
- 23 Non-abundant sums - Project Euler
- 折半查找
- SpringMVC + servlet3.0 文件上传的配置和实现
- Android Scroller 的简单用法
- 编写一个函数,当n为偶数的时候,输入n偶数是调用1/2+1/4........当n为奇数的时候调用1/1+1/3+1/5
- vs2012 error c4996: 'fopen': This function or variable may be unsafe
- iRate快速绕坑使用
- [iOS]BOOL / bool / Boolean / NSCFBoolean
- iRate快速绕坑使用