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次都是不变的。
顺时针旋转:
![](https://img-blog.csdn.net/20140311122032890?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl0dGxlX19wb3RhdG8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
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
![](https://img-blog.csdn.net/20140311122055093?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl0dGxlX19wb3RhdG8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
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
![](https://img-blog.csdn.net/20140311122114093?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl0dGxlX19wb3RhdG8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
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
代码参考:
题目大意:给出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 400C - Inna and Huge Candy Matrix(耐心找规律,细节还是要注意的)
- Codeforces 400C Inna and Huge Candy Matrix
- Codeforces 400C Inna and Huge Candy Matrix 【模拟】
- codeforces 400C Inna and Huge Candy Matrix
- Codeforces 400C Inna and Huge Candy Matrix(模拟)
- codeforces 400 C Inna and Huge Candy Matrix【模拟】
- CF 400C - Inna and Huge Candy Matrix
- Codeforces 400 C. Inna and Huge Candy Matrix
- Codeforces 400B Inna and Huge Candy Matrix(模拟)
- Codeforces 400 C. Inna and Huge Candy Matrix【 Codeforces Round #234 (Div. 2)】
- C. Inna and Huge Candy Matrix(cf)
- C - Inna and Huge Candy Matrix
- codeforces Inna and Huge Candy Matrix
- codeforces C. Inna and Huge Candy Matrix
- (CF)C. Inna and Huge Candy Matrix
- codeforces round #234B(DIV2) C Inna and Huge Candy Matrix
- codeforces 390D Inna and Sweet Matrix
- Codeforces 390C Inna and Candy Boxes RMQ简单变化 或 前缀和dp一下
- codeforces 400B - Inna and New Matrix of Candies
- Codeforces 400B Inna and New Matrix of Candies 【模拟】