本文主要是介绍Codeforces 400C Inna and Huge Candy Matrix(模拟),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接: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(模拟)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!