shunfurh 于 2017.01.03 15:08 提问

Flip and Turn

Description

Let us define a set of operations on a rectangular matrix of printable characters.

A matrix A with m rows (1-st index) and n columns (2-nd index) is given. The resulting matrix B is defined as follows.

Transposition by the main diagonal (operation identifier is ‘1’): Bj,i = Ai,j
Transposition by the second diagonal (‘2’): Bn−j+1,m−i+1 = Ai,j
Horizontal flip (‘H’): Bm−i+1,j = Ai,j
Vertical flip (‘V’): Bi,n−j+1 = Ai,j
Rotation by 90 (‘A’), 180 (‘B’), or 270 (‘C’) degrees clockwise; 90 degrees case: Bj,m−i+1 = Ai,j
Rotation by 90 (‘X’), 180 (‘Y’), or 270 (‘Z’) degrees counterclockwise; 90 degrees case: Bn−j+1,i = Ai,j
You are given a sequence of no more than 100 000 operations from the set. Apply the operations to the given matrix and output the resulting matrix.

Input

At the first line of the input file there are two integer numbers — m and n (0 < m, n ≤ 300). Then there are m lines with n printable characters per line (we define a printable character as a symbol with ASCII code from 33 to 126 inclusive). There will be no additional symbols at these lines.

The next line contains the sequence operations to be performed, specified by their one-character identifiers. The operations should be performed from left to right.

Output

Two integer numbers, the number of rows and columns in the output matrix. Then the output matrix must follow, in the same format as the input one.

Sample Input

3 4
0000
a0b0
cdef
A1
Sample Output

3 4
cdef
a0b0
0000

1个回答

caozhy      2017.01.09 23:53

POJ 3106 Flip and Turn

POJ-3106 Flip and Turn （模拟）
【题目大意】给你一个n*m的矩阵，然后给你一系列操作，最后让你输出操作后的矩阵。操作包括：1：沿主对角线反转2：沿副对角线反转H：上下翻转V：水平翻转A B C：顺时针90° 180° 270°X Y Z：逆时针。操作数量k&amp;lt;=100 000，n&amp;lt;=300。【分析】直接暴力是O(k*n^2)，TLE。可以用一个2*2的矩阵，每一次对这个矩阵操作，最后在根据这个矩阵对所给矩阵进行同样的操...
A - Flip and Turn
A - Flip and Turn POJ - 3106 #include &amp;lt;iostream&amp;gt;#include &amp;lt;string&amp;gt;#include &amp;lt;cstring&amp;gt;#include &amp;lt;cstdio&amp;gt;using namespace std;char a[309][309];char b[309][309];char cp[7][3]= {&quot;1&quot;,&quot;C...
POJ 3106 Flip and Turn 笔记
m*n的字符矩阵。可对矩阵进行如下操作：主对角线转置（1）。第二对角线转置（2）。水平翻转（H）。垂直翻转（V）。顺时针旋转90度（A），180（B），270（C）。逆时针旋转90度（X），180（Y），270（Z）。求结果矩阵。

OpenCV代码提取：flip函数的实现
OpenCV代码提取：flip函数的实现
java.nio.Buffer 中的 flip()方法

NIO之Buffer的clear()、rewind()、flip()方法的区别
Java的NIO中有关Buffer的几种常用方法比如clear,rewind和flip到底有哪些区别。下面给大家这三种方法的源码，方便大家记忆。 clear()方法用于写模式，其作用为情况Buffer中的内容，所谓清空是指写上限与Buffer的真实容量相同，即limit==capacity,同时将当前写位置置为最前端下标为0处。代码如下： public final Buffer clear()
ATMEL FLIP的使用步骤

ByteBuffer.flip()注意细节
<br />ByteBuffer.flip() <br />反转此缓冲区。首先将限制设置为当前位置，然后将位置设置为 0。如果已定义了标记，则丢弃该标记。 在一系列通道读取或放置 操作之后，调用此方法为一系列通道写入或相对获取 操作做好准备。<br />例如： <br /> buf.put(magic);// Prepend header <br />in.read(buf); // Read data into rest of buffer<br /> buf.flip();