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

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <algorithm>
 5 using namespace std;
 6
 7 int n, m;
 8 int x, y;
 9
10 void clockwise(int cnt)
11 {
12     for (int i = 1; i <= cnt; i++)
13     {
14         int t = x;
15         x = y;
16         y = n-t+1;
17         swap(n, m);
18     }
19 }
20
21 void hor_rotate()
22 {
23     y = m - y + 1;
24 }
25
26 void counterclockwise(int cnt)
27 {
28     for (int i = 1; i <= cnt; i++)
29     {
30         int t = x;
31         x = m - y + 1;
32         y = t;
33         swap(n, m);
34     }
35 }
36
37 int main()
38 {
39     int i, a, b, c, p;
40     while (scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &p) != EOF)
41     {
42         int tn, tm;
43         tn = n;
44         tm = m;
45         for (i = 1; i <= p; i++)
46         {
47             n = tn;
48             m = tm;
49             scanf("%d%d", &x, &y);
50             if (a % 4)
51                 clockwise(a%4);
52             if (b % 2)
53                hor_rotate();
54             if (c % 4)
55                 counterclockwise(c%4);
56             printf("%d %d\n", x, y);
57         }
58     }
59     return 0;
60 }

转载于:https://www.cnblogs.com/windysai/p/3618255.html

codeforces C. Inna and Huge Candy Matrix 解题报告相关推荐

  1. CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段)

    CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段) 树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且 ...

  2. Codeforces Round #697 (Div. 3)A~G解题报告

    Codeforces Round #697 (Div. 3)A~G解题报告 题 A Odd Divisor 题目介绍 解题思路 乍一想本题,感觉有点迷迷糊糊,但是证难则反,直接考虑没有奇数因子的情况, ...

  3. Codeforces Round #700 (Div. 2)A~D2解题报告

    Codeforces Round #700 (Div. 2)A~D2解题报告 A Yet Another String Game 原题链接 http://codeforces.com/contest/ ...

  4. Codeforces Round #693 (Div. 3)A~G解题报告

    Codeforces Round #693 (Div. 3)A~G解题报告 A Cards for Friends 原题信息 http://codeforces.com/contest/1472/pr ...

  5. 【LeetCode】723. Candy Crush 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 日期 题目地址:https://leetcode ...

  6. Codeforces Round #827 (Div. 4) G. Orray 解题报告

    原题链接: Problem - G - Codeforces 题目描述: You are given an array aa consisting of nn nonnegative integers ...

  7. codeforces 814B.An express train to reveries 解题报告

    题目链接:http://codeforces.com/problemset/problem/814/B 题目意思:分别给定一个长度为 n 的不相同序列 a 和 b.这两个序列至少有 i 个位置(1 ≤ ...

  8. Codeforces Round #830 (Div. 2) B. Ugu 解题报告

    原题链接: Problem - B - Codeforces 题目描述: A binary string is a string consisting only of the characters 0 ...

  9. Codeforces Round #626(Div.2) 解题报告

    Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) [前言] 最近沉迷只狼,好久没有打CF了,水平 ...

最新文章

  1. 【万字长文】吃透负载均衡
  2. [Hadoop in China 2011] Facebook Message在HBase基础上的应用
  3. 安卓动态.9图拉伸实现方案
  4. 转载 从SRAM中读写一个数据问题——Verilog
  5. 读《构建之法》1-5章
  6. java 排序原理_简单选择排序算法原理及java实现(超详细)
  7. Android权限Uri.parse总结
  8. 腾讯视频网页下载_腾讯视频怎么下载视频
  9. jQuery EasyUI combobox多选及赋值
  10. bcc挖矿用什么_IPFS挖矿与传统传统挖矿的区别
  11. 商业智能改变汽车行业
  12. JadClipse反编译工具在Eclipse中的安装
  13. 智能AI文章伪原创工具免费使用注意事项与推荐
  14. 二维码和一维码生成器
  15. OpenCV_连通区域分析(Connected Component Analysis-Labeling)
  16. cpufreq 频率设置verify
  17. 幽默的最高境界——这才叫幽默
  18. 简述分布式锁的3种实现方式
  19. c++小游戏杀手1.1.1版本
  20. 微信小程序时代已经来临

热门文章

  1. Nginx配置wss访问实现微信小程序的websocket通信
  2. Vscode使用npm安装babel
  3. Mr.J---重拾Ajax(一)--XMLHttpRequest
  4. 血的教训--如何正确使用线程池submit和execute方法
  5. 关于linux下的命令
  6. CSS可见区域全局居中
  7. kaptcha小案例(转)
  8. java面对对象 关键字this super
  9. 0.8.11版本ffmpeg一天移植将近完成。
  10. 6个很棒的PostCSS插件,让您成为一个CSS向导