码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces400C

时间:2019-07-07 22:43:55      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:tchar   asd   input   title   idt   ima   sdi   struct   gre   

Inna and Huge Candy Matrix

 CodeForces - 400C 

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 nmxyzp (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).

Each of the following p lines contains two integers xkyk (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.

Examples

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

sol:题意简单清晰,只要膜过以后暴力模拟即可
技术图片
/*
题目大意:给出n,m,x,y,z和p,表示在一个n*m的矩阵上有p块糖果,
给出p块糖果的坐标,然后将整个矩阵顺时针旋转x次,镜像翻转y次,
逆时针旋转z次,然后按照顺序输出操作完后糖果的坐标.
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0;
    bool f=0;
    char ch= ;
    while(!isdigit(ch))
    {
        f|=(ch==-); ch=getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
    }
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0)
    {
        putchar(-); x=-x;
    }
    if(x<10)
    {
        putchar(x+0); return;
    }
    write(x/10);
    putchar((x%10)+0);
    return;
}
#define W(x) write(x),putchar(‘ ‘)
#define Wl(x) write(x),putchar(‘\n‘)
const int N=100005;
int n,m,X,Y,Z,cnt;
struct Point
{
    int x,y;
}P[N];
inline void SSZ()
{
    int i;
    for(i=1;i<=cnt;i++)
    {
        int xx=P[i].x,yy=P[i].y;
        P[i].x=yy; P[i].y=n-xx+1;
    }
    swap(n,m);
}
inline void JX()
{
    int i;
    for(i=1;i<=cnt;i++) P[i].y=m-P[i].y+1;
}
inline void NSZ()
{
    int i;
    for(i=1;i<=cnt;i++)
    {
        int xx=P[i].x,yy=P[i].y;
        P[i].x=m-yy+1; P[i].y=xx;
    }
    swap(n,m);
}
int main()
{
    int i;
    R(n); R(m); R(X); R(Y); R(Z); R(cnt);
    for(i=1;i<=cnt;i++) {R(P[i].x); R(P[i].y);}
    X%=4; Y%=2; Z%=4;
    for(i=1;i<=X;i++) SSZ();
    for(i=1;i<=Y;i++) JX();
    for(i=1;i<=Z;i++) NSZ();
    for(i=1;i<=cnt;i++) W(P[i].x),Wl(P[i].y);
    return 0;
}
/*
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
*/
View Code

 

 

codeforces400C

标签:tchar   asd   input   title   idt   ima   sdi   struct   gre   

原文地址:https://www.cnblogs.com/gaojunonly1/p/11148324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!