codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

400C.md (2315B)


      1 Source: https://codeforces.com/problemset/problem/400/C
      2 
      3 C. Inna and Huge Candy Matrix
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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 (*x**k*, *y**k*).
     22 
     23 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.
     24 
     25  ![](https://espresso.codeforces.com/e7568007666c15d51c557727576c388a0017fbed.png) 
     26 
     27 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!
     28 
     29 Input
     30 
     31 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).
     32 
     33 Each of the following *p* lines contains two integers *x**k*, *y**k* (1 ≤ *x**k* ≤ *n*; 1 ≤ *y**k* ≤ *m*) — the initial coordinates of the *k*-th candy. Two candies can lie on the same cell.
     34 
     35 Output
     36 
     37 For each of the *p* candies, print on a single line its space-separated new coordinates.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 3 3 3 1 1 9  
     45 1 1  
     46 1 2  
     47 1 3  
     48 2 1  
     49 2 2  
     50 2 3  
     51 3 1  
     52 3 2  
     53 3 3
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 1 3  
     60 1 2  
     61 1 1  
     62 2 3  
     63 2 2  
     64 2 1  
     65 3 3  
     66 3 2  
     67 3 1
     68 ```
     69 
     70 Note
     71 
     72 Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
     73 
     74 ```
     75 QWER      REWQ   
     76 ASDF  ->  FDSA  
     77 ZXCV      VCXZ
     78 ```