zoukankan      html  css  js  c++  java
  • 二维坐标旋转

    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 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.

    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,而有多组数据处理所以令a=n,b=m,旋转中交换a,b的值
    #include <iostream>
    #include <cstdio>
    using namespace std;
    int n,m,x,y,z;
    int s1,s2;
    int a,b;
    
    void xuan(int k)
    {
        int i;
        int t;
        for(i=1;i<=k;i++) 旋转多次(s1,s2)-->(s2,n+1-s1)
        {
            t=s1;
            s1=s2;
            s2=a+1-t;
            t=a;
            a=b;
            b=t;
        }
    }
    
    int main()
    {
        int p;
        while(cin>>n>>m>>x>>y>>z>>p)
        {
            x=x%4;
            y=y%2;
            z=z%4;
            z=(4-z)%4;
            while(p--)
            {
                a=n;b=m;
                scanf("%d%d",&s1,&s2);
                xuan(x);
                if(y==1)
               {
                  s2=b-s2+1;
               }
                xuan(z);
                cout<<s1<<" "<<s2<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    (难)Codeforces Round #406 (Div. 2) C题Berzerk(有向图博弈)解题报告
    jquery清空kindEditor
    处理用户误输入html标签引起的网站布局混乱
    自动闭合所有标签的方法,用于获得textBox等值的时候,标签都是闭合的
    .NET一个页面多个Button按钮事件避免数据验证控件RequiredFieldValidator
    基类包括字段(),但其类型()与控件()的类型不兼容
    关于ajax回调数据类型为Json,如何获得他的值
    如何查找Repeater控件中嵌套的控件
    网站功能
    WIN7系统IIS上发布站点后水印效果失效的解决方法
  • 原文地址:https://www.cnblogs.com/chen9510/p/4927869.html
Copyright © 2011-2022 走看看