codeforces C. Inna and Huge Candy Matrix 解题报告
题目链接: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 解题报告的更多相关文章
- codeforces C. Inna and Huge Candy Matrix
http://codeforces.com/problemset/problem/400/C 题意:给你一个n*m的矩阵,然后在矩阵中有p个糖果,给你每个糖果的初始位置,然后经过x次顺时针反转,y次旋 ...
- codeforces round #234B(DIV2) C Inna and Huge Candy Matrix
#include <iostream> #include <vector> #include <algorithm> #include <utility> ...
- codeforces 400 C Inna and Huge Candy Matrix【模拟】
题意:给出一个矩形的三种操作,顺时针旋转,逆时针旋转,对称,给出原始坐标,再给出操作数,问最后得到的坐标 画一下模拟一下操作就可以找到规律了 #include<iostream> #inc ...
- codeforces B. Polo the Penguin and Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/289/B 题目意思:给出一个 n 行 m 列的矩阵和数值 d .通过对矩阵里面的数进行 + d 或者 - ...
- 【LeetCode】01 Matrix 解题报告
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/descripti ...
- 【LeetCode】378. Kth Smallest Element in a Sorted Matrix 解题报告(Python)
[LeetCode]378. Kth Smallest Element in a Sorted Matrix 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...
- codeforces C. Ilya and Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/313/C 题目意思:给定 4n 个整数(可以组成 2n × 2n 大小的矩阵),问通过对这些整数进行排列, ...
- codeforces 486B.OR in Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...
- codeforces A. Candy Bags 解题报告
题目链接:http://codeforces.com/contest/334/problem/A 题意:有n个人,将1-n袋(第 i 袋共有 i 颗糖果,1<= i <=n)所有的糖 ...
随机推荐
- 提高速度 history 的利用
history的介绍history是shell的内置命令,其内容在系统默认的shell的man手册中.history是显示在终端输入并执行的过命令,系统默认保留1000条.[root@localhos ...
- mysql function
mysql 自定义函数的使用 先查看函数功能是否开启:show variables like '%func%'; 若是未开启则:SET GLOBAL log_bin_trust_function_cr ...
- fastjson的序列化属性
在将使用JSON.toJSONString(result, SerializerFeature.PrettyFormat)将JSONObject转化为字符串时,可以指定一些序列化属性,设置转化后的字符 ...
- session再次理解
1.session介绍: session主要用来存储用户的会话所需的信息(用户行为信息),当用户在同一个服务器上实现不同的操作时,session信息会以变量的形式存储在服务器的内存中,保存用户的状态信 ...
- 使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在方法调用之前决定是否开启一个事务,并在方法执行之后决定事务提交或回滚事务。
使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在方法调用之前决定是否开启一个事务,并在方法执行之后决定事务提交或回滚事务.
- 解决mac osx下pip安装ipython权限的问题
1 pip install ipython --user -U 下面是pip install gevent的错误提示, 又是 Operation not permitted … 1 2 3 4 5 ...
- C# 通过WebService方式 IIS发布网站 上传文件到服务器[转]
http://blog.sina.com.cn/s/blog_517cae3c0102v0y7.html 应用场景:要将本地的文件 上传到服务器的虚拟机上 网络环境:公司局域网(如下图中第二种) 开发 ...
- JavaScript校验输入的字符串是否包含特殊字符
校验在文本框输入的字符串中是否包含特殊字符串,js代码如下 function strInclude(substring){ if(substring){ var reg = new RegExp(&q ...
- HDU 4635 Strongly connected(强连通)经典
Strongly connected Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 将iconv编译成lua接口
前一篇博文说了.在cocos2dx中怎么样使用iconv转码,这节我们将上一节中写的转码函数,做成一个lua接口.在lua脚本中使用. 网上能够下载到luaconv.可是编译的时候总是报错,所以自己写 ...