題目鏈接:http://codeforces.com/problemset/problem/400/C
題目大意:給出n,m,x,y,z,p,n*m的矩陣上有p塊糖果,給出p塊糖果的座標,輸出矩陣順時針旋轉x次,鏡像翻轉y次,逆時針旋轉z次後糖果座標。
題目分析:旋轉完n和m要交換,翻轉不用,旋轉4次和翻轉2次都是不變的。
順時針旋轉:
n=3, m=2
(1,1)->(1,3) (1,2)->(2,3)
(2,1)->(1,2) (2,2)->(2,2)
(3,1)->(1,1) (3,2)->(2,1)
得到規律:x'=y,y'=1+n-x
n=3, m=2
(1,1)->(1,2) (1,2)->(1,1)
(2,1)->(2,2) (2,2)->(2,1)
(3,1)->(3,2) (3,2)->(3,1)
得到規律:x'=x,y'=n-y
(1,1)->(2,1) (1,2)->(1,1)
(2,1)->(2,2) (2,2)->(1,2)
(3,1)->(2,3) (3,2)->(1,3)
得到規律:x'=m+1-y,y'=x
代碼參考:
#include<set>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5+9;
struct Point
{
int x, y;
}pos[N];
int n, m, x, y, z, p;
void clockwise()
{
int x, y;
for(int i=0; i<p; ++i)
{
x = pos[i].y;
y = 1+n-pos[i].x;
pos[i].x = x;
pos[i].y = y;
}
swap(n, m);
}
void horizontal()
{
for(int i=0; i<p; ++i)
{
pos[i].y = m+1-pos[i].y;
}
}
void counter()
{
int x, y;
for(int i=0; i<p; ++i)
{
x = m+1-pos[i].y;
y = pos[i].x;
pos[i].x = x;
pos[i].y = y;
}
swap(n, m);
}
int main()
{
int i, j, a, b;
while(~scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p))
{
for(i=0; i<p; ++i)
{
scanf("%d%d", &pos[i].x, &pos[i].y);
}
for(i=0; i<x%4; ++i) clockwise();
for(i=0; i<y%2; ++i) horizontal();
for(i=0; i<z%4; ++i) counter();
for(i=0; i<p; ++i)
{
printf("%d %d\n", pos[i].x, pos[i].y);
}
}
return 0;
}