POJ 3106Flip and Turn(模擬)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 957 | Accepted: 330 |
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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
char a[305][305];
char b[305][305];
char str[100005];
int m,n;
int tb[3][3];
void con1()
{
int i,j;
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
b[i][j]=a[j][i];
}
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
a[i][j]=b[i][j];
a[i][j]='\0';
}
swap(n,m);
}
void con2()
{
int i,j;
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
b[n-j+1][m-i+1]=a[i][j];
}
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
a[i][j]=b[i][j];
a[i][j]='\0';
}
swap(n,m);
}
void con3()
{
int i,j;
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
b[m-i+1][j]=a[i][j];
}
}
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
a[i][j]=b[i][j];
a[i][j]='\0';
}
}
void con4()
{
int i,j;
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
b[i][n-j+1]=a[i][j];
}
}
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
a[i][j]=b[i][j];
a[i][j]='\0';
}
}
void con5()
{
int i,j;
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
b[j][m-i+1]=a[i][j];
}
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
a[i][j]=b[i][j];
a[i][j]='\0';
}
swap(m,n);
}
void con6()
{
int i,j;
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
b[n-j+1][i]=a[i][j];
}
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
a[i][j]=b[i][j];
a[i][j]='\0';
}
swap(m,n);
}
void debug()
{
int i,j;
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
cout<<tb[i][j]<<" ";
cout<<endl;
}
}
int main()
{
int i,j;
while(~scanf("%d%d",&m,&n))
{
for(i=1; i<=m; i++)
scanf("%s",a[i]+1);
scanf("%s",str);
tb[1][1]=1,tb[1][2]=2,tb[2][1]=3,tb[2][2]=4;
for(i=0; i<strlen(str); i++)
{
if(str[i]=='1')
{
swap(tb[1][2],tb[2][1]);
}
else if(str[i]=='2')
{
swap(tb[1][1],tb[2][2]);
}
else if(str[i]=='H')
{
swap(tb[1][1],tb[2][1]);
swap(tb[1][2],tb[2][2]);
}
else if(str[i]=='V')
{
swap(tb[1][1],tb[1][2]);
swap(tb[2][1],tb[2][2]);
}
else if(str[i]>='A'&&str[i]<='C')
{
int s=str[i]-'A'+1;
for(j=0;j<s;j++)
{
swap(tb[2][2],tb[1][2]);
swap(tb[1][1],tb[1][2]);
swap(tb[1][1],tb[2][1]);
}
}
else if(str[i]>='X'&&str[i]<='Z')
{
int s=str[i]-'X'+1;
for(j=0;j<s;j++)
{
swap(tb[1][1],tb[2][1]);
swap(tb[1][1],tb[1][2]);
swap(tb[2][2],tb[1][2]);
}
}
}
//debug();
//是中心對稱,順時針轉,對稱轉,沿對角線折都是中心對稱,所以1 4只能是對角
if(tb[1][1]==1&&tb[1][2]==2&&tb[2][1]==3&&tb[2][2]==4) {} // 1 2 3 4
else if(tb[1][1]==1&&tb[1][2]==3&&tb[2][1]==2&&tb[2][2]==4) con1(); //1 3 2 4
else if(tb[1][1]==2&&tb[1][2]==1&&tb[2][1]==4&&tb[2][2]==3) con4(); //2 1 4 3
else if(tb[1][1]==3&&tb[1][2]==1&&tb[2][1]==4&&tb[2][2]==2) con5(); //3 1 4 2
else if(tb[1][1]==4&&tb[1][2]==2&&tb[2][1]==3&&tb[2][2]==1) con2(); //4 2 3 1
else if(tb[1][1]==4&&tb[1][2]==3&&tb[2][1]==2&&tb[2][2]==1) {con2(); con1();} //4 3 2 1
else if(tb[1][1]==2&&tb[1][2]==4&&tb[2][1]==1&&tb[2][2]==3) con6(); //2 4 1 3
else if(tb[1][1]==3&&tb[1][2]==4&&tb[2][1]==1&&tb[2][2]==2) {con6(); con2();} //3 4 1 2
cout<<m<<" "<<n<<endl;
for(i=1; i<=m; i++)
cout<<a[i]+1<<endl;
}
return 0;
}
/*
3 4
0000
a0b0
cdef
A1
*/
相關文章
- Parencodings(POJ 1068)(模擬)Encoding
- POJ 2259 Team Queue【模擬佇列】佇列
- POJ——1016Parencodings(模擬)Encoding
- POJ 1068-Parencodings(模擬-包含括號個數)Encoding
- POJ 2996-Help Me with the Game(模擬-描述棋盤中KQRBNP的位置)996GAM
- 模擬
- 10.6 模擬賽(NOIP 模擬賽 #9)
- 有限元模擬 有限體積模擬
- POJ-1581 A Contesting Decision-模擬ACM比賽時的評分規則ACM
- git 模擬Git
- 模擬題
- ACP模擬
- 模擬賽
- about materialized view and long(turn)ZedView
- Keil的軟體模擬和硬體模擬
- Thinking in Java---多執行緒模擬:銀行出納員模擬+飯店模擬+汽車裝配工廠模擬ThinkingJava執行緒
- Gpssworld模擬(二):並排排隊系統模擬
- Altair SimSolid 工程模擬軟體 衡祖模擬AISolid
- PID除錯軟體(C#、模擬、模擬)除錯C#
- 「模擬賽」暑期集訓CSP提高模擬10(7.28)
- 「模擬賽」暑期集訓CSP提高模擬15(8.7)
- REST is not enabled. use -rest to turn onREST
- NOIP模擬50
- NOIP模擬57
- iOS 模擬器iOS
- NOIP模擬74
- NOIP模擬76
- NOIP模擬77
- NOIP模擬66
- 模擬面試題面試題
- 模擬退火原理
- 5.4 模擬賽
- CSP模擬3
- noip模擬1
- 模擬鬥地主
- noip模擬3
- noip模擬4
- 8.5 模擬賽