首页 > 其他 > 详细

Codeforces 400C Inna and Huge Candy Matrix(模拟)

时间:2014-03-06 17:35:39      阅读:480      评论:0      收藏:0      [点我收藏+]

题目链接: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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!