您的位置:首页 > 其它

codeforces 400C - Inna and Huge Candy Matrix

2014-03-07 12:32 387 查看
题目链接: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



n=3, m=2
(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
;
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces