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