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

最新文章

  1. 通过拦截器Interceptor实现Spring MVC中Controller接口访问信息的记录
  2. 20款响应式的 HTML5 网页模板【免费下载】
  3. Android4.0窗口机制和创建过程分析
  4. Swift - IBOutlet返回nil(fatal error: unexpectedly found nil while unwrapping an Optional value)
  5. centos vim的安装目录在哪里
  6. Openstack service default port
  7. 在SSIS包中使用 Checkpoint从失败处重新启动包
  8. Weex系列二、显示图片
  9. Nginx之(一)Nginx是什么
  10. 《前端之路》之五 head 头标签指南
  11. Git使用详细教程(5):修改提交说明
  12. PHP 3种方法实现采集网站数据
  13. AngularJS集合数据遍历显示
  14. 【git】git一些命令使用记录
  15. [No0000196]一文读懂Java 11的ZGC为何如此高效
  16. webkit技术内幕读书笔记 (一)
  17. 【转】RTMP/RTP/RTSP/RTCP协议对比与区别介绍
  18. EBS 11i升级R12
  19. BitAdminCore框架更新日志20180518
  20. CCF 201709-2公共钥匙盒

热门文章

  1. BZOJ1001[BeiJing2006]狼抓兔子最小割網絡流
  2. linux mysql添加用户名并实现远程访问
  3. MySQL 服务无法启动-问题处理
  4. 【js】小数点后保留两位小数
  5. 高通msm8994启动流程简单介绍
  6. 【翻译自mos文章】当并行事务恢复进程在执行时,禁用并行事务恢复的方法
  7. iphone越狱-------平刷回越狱前(未越狱)状态
  8. C/C++中怎样获取日期和时间
  9. PHP计算两个时间差的方法
  10. caffeModels--models-caffes-大全