题目链接:http://codeforces.com/problemset/problem/400/C

题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal rotate 和z次counterclockwise 之后,原来在n行m列的矩阵的坐标去到哪个位置。

题目意思很容易看懂。易知,对于clockwise,counterclockwise的次数,mod 4 == 0 相当于没有改变!而对于 horizontal rotate,mod 2 == 0 也是没有改变的!

假设问的坐标是(i, j),那么经过一次clockwise的转变,坐标变为(j, n-i+1),交换 n 和 m 值。

经过一次 horizontal rotate,坐标为(i, m-j+1)

经过一次counterclockwise,坐标为(m-j+1, i),交换 n 和 m 值

特别要注意,计算完一个点的位置之后,n和m有可能与原始输入的n和m的值不同,因此需要记录原始输入的 n 和 m !!!因为题目问的是原始输入下的每个坐标点经过x,y,z次转换后的位置,并不是在计算完上一个坐标点后调整过的n 和 m。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std; int n, m;
int x, y; void clockwise(int cnt)
{
for (int i = ; i <= cnt; i++)
{
int t = x;
x = y;
y = n-t+;
swap(n, m);
}
} void hor_rotate()
{
y = m - y + ;
} void counterclockwise(int cnt)
{
for (int i = ; i <= cnt; i++)
{
int t = x;
x = m - y + ;
y = t;
swap(n, m);
}
} int main()
{
int i, a, b, c, p;
while (scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &p) != EOF)
{
int tn, tm;
tn = n;
tm = m;
for (i = ; i <= p; i++)
{
n = tn;
m = tm;
scanf("%d%d", &x, &y);
if (a % )
clockwise(a%);
if (b % )
hor_rotate();
if (c % )
counterclockwise(c%);
printf("%d %d\n", x, y);
}
}
return ;
}

codeforces C. Inna and Huge Candy Matrix 解题报告的更多相关文章

  1. codeforces C. Inna and Huge Candy Matrix

    http://codeforces.com/problemset/problem/400/C 题意:给你一个n*m的矩阵,然后在矩阵中有p个糖果,给你每个糖果的初始位置,然后经过x次顺时针反转,y次旋 ...

  2. codeforces round #234B(DIV2) C Inna and Huge Candy Matrix

    #include <iostream> #include <vector> #include <algorithm> #include <utility> ...

  3. codeforces 400 C Inna and Huge Candy Matrix【模拟】

    题意:给出一个矩形的三种操作,顺时针旋转,逆时针旋转,对称,给出原始坐标,再给出操作数,问最后得到的坐标 画一下模拟一下操作就可以找到规律了 #include<iostream> #inc ...

  4. codeforces B. Polo the Penguin and Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/289/B 题目意思:给出一个 n 行 m 列的矩阵和数值 d .通过对矩阵里面的数进行 + d 或者 - ...

  5. 【LeetCode】01 Matrix 解题报告

    [LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/descripti ...

  6. 【LeetCode】378. Kth Smallest Element in a Sorted Matrix 解题报告(Python)

    [LeetCode]378. Kth Smallest Element in a Sorted Matrix 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...

  7. codeforces C. Ilya and Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/313/C 题目意思:给定 4n 个整数(可以组成 2n × 2n 大小的矩阵),问通过对这些整数进行排列, ...

  8. codeforces 486B.OR in Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...

  9. codeforces A. Candy Bags 解题报告

    题目链接:http://codeforces.com/contest/334/problem/A 题意:有n个人,将1-n袋(第 i  袋共有 i  颗糖果,1<= i  <=n)所有的糖 ...

随机推荐

  1. XSY1659 [HNOI2012]永无乡

    题面 Description 永无乡包含 n 座岛,编号从 1 到 n. 每座岛都有自己的独一无二的重要度,按照重要度可以将这n座岛排名,名次用 1到n来表示.某些岛之间由巨大的桥连接,通过桥可以从一 ...

  2. PyTorch学习笔记之Tensors 2

    Tensors的一些应用 ''' Tensors和numpy中的ndarrays较为相似, 因此Tensor也能够使用GPU来加速运算 ''' # from _future_ import print ...

  3. Maven修改默认本地资源库文件夹

    默认的Maven地址如下: Linux/Mac:~/.m2(提示:~/为当前用户目录地址) Widnows:C:\Users\{username}\.m2(提示:username为当前用户名) 修改操 ...

  4. eclipse项目java版本更改

    然后.右键点击项目->properties->Java Compiler->....如图 ​ 最后,右键点击项目->properties->Project  Facets ...

  5. arcgis andriod 加载影像

    MapView mMapView;......String rasterPath = Environment.getExternalStorageDirectory().getPath() + &qu ...

  6. 1.【nuxt起步】-nuxt是什么?

    百度了解下,简单说就是vue的seo化,因为vue是spa,不支持seo,从本地运行的源码可以看出来,html没有tkd和相关文字,导致百度收录困难,所以nuxt可以很好的解决这个问题, 举个例子:纯 ...

  7. 【Todo】Java并发学习 & 示例练习及代码

    接上一篇:http://www.cnblogs.com/charlesblc/p/6097111.html <Java并发学习 & Executor学习 & 异常逃逸 & ...

  8. windows forget jenkins password.

    1. goto the directory of jenkins. for example my installation is in D:\Program Files (x86)\Jenkins. ...

  9. 我的跟我学Ffmpeg 视频受众有哪些人

    经常有人问我如何学习音视频以及如何学习Ffmpeg,问我有没有比较好的书的书推荐.比较好的音视频以及FFmpeg方面的 书,我了解到的比较全面又能深入浅出的还真没有.很多朋友都推荐雷神的博客,雷神的博 ...

  10. DataTable和DataRow利用反射直接转换为Model对象的扩展方法类

    DataTable和DataRow利用反射直接转换为Model对象的扩展方法类   /// <summary> /// 类 说 明:给DataTable和DataRow扩展方法,直接转换为 ...