题目链接:Codeforces 400C Inna and Huge Candy Matrix
题目大意:给出n,m,x,y,z和p,表示在一个n*m的矩阵上有p块糖果,给出p块糖果的坐标,然后将整个矩阵顺时针旋转x次,镜像翻转y次,逆时针旋转z次,然后按照顺序输出操作完后糖果的坐标。
解题思路:模拟,注意旋转完,n和m要交换,翻转不用,然后如果纯模拟肯定超时,很容易发现旋转4次等于没变,翻转2次也是没有变的。
#include <stdio.h> #include <string.h> const int N = 1e5+5; struct state { int xi, yi; }s[N]; int n, m, x, y, z, p; void cw() { for (int i = 0; i < p; i++) { int r = s[i].yi; int l = n + 1 - s[i].xi; s[i].xi = r; s[i].yi = l; } int t = n; n = m; m = t; } void hr() { for (int i = 0; i < p; i++) s[i].yi = m + 1 - s[i].yi; } void ccw() { for (int i = 0; i < p; i++) { int r = m + 1 - s[i].yi; int l = s[i].xi; s[i].xi = r; s[i].yi = l; } int t = n; n = m; m = t; } int main () { scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p); for (int i = 0; i < p; i++) scanf("%d%d", &s[i].xi, &s[i].yi); x %= 4; for (int i = 0; i < x; i++) cw(); y %= 2; for (int i = 0; i < y; i++) hr(); z %= 4; for (int i = 0; i < z; i++) ccw(); for (int i = 0; i < p; i++) printf("%d %d\n", s[i].xi, s[i].yi); return 0; }
Codeforces 400C Inna and Huge Candy Matrix(模拟),布布扣,bubuko.com
Codeforces 400C Inna and Huge Candy Matrix(模拟)
原文:http://blog.csdn.net/keshuai19940722/article/details/20626511