P2630 图像变换
题目描述
给定 33 行 33 列的图像各像素点灰度值,给定最终图像,求最短、字典序最小的操作序列。
其中,可能的操作及对应字符有如下四种:
A:顺时针旋转 9090 度;
B:逆时针旋转 9090 度;
C:左右翻转;
D:上下翻转。
输入格式
一个矩阵,表示初始的图像。
一个矩阵,表示最终的图像。
输出格式
最短、字典序最小的操作序列,保证长度不超过 10^8,不保证有解。
若长度不超过 10^8
无解则输出 Poland cannot into space!!! 。
输入输出样例
输入 #1
3 4 5
6 7 8
1 2 3
1 2 3
6 7 8
3 4 5
输出 #1
D
说明/提示
字符串长度不超过 10^8
// 总结:没有理清多次旋转之间的对应关系,以及组合变换之间的对应关系
/**
* ID: W_208YE
* LANG: C++11
* PROG: ride
*/
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define pii pair<int, int>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXK = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
int t, n;
void A(int x[4][4]) {
int temp = x[1][2];
x[1][2] = x[2][1];
x[2][1] = x[3][2];
x[3][2] = x[2][3];
x[2][3] = temp;
temp = x[1][1];
x[1][1] = x[3][1];
x[3][1] = x[3][3];
x[3][3] = x[1][3];
x[1][3] = temp;
}
// void B(int x[4][4]) { // 三次A为一次B
// int temp = x[1][2];
// x[1][2] = x[2][3];
// x[2][3] = x[3][2];
// x[3][2] = x[2][1];
// x[2][1] = temp;
// temp = x[1][1];
// x[1][1] = x[1][3];
// x[1][3] = x[3][3];
// x[3][3] = x[3][1];
// x[3][1] = temp;
// }
void C(int x[4][4]) { // 左右
for (int i = 1; i <= 3; ++i)
swap(x[i][1], x[i][3]);
}
void D(int x[4][4]) { // 上下
for (int i = 1; i <= 3; ++i)
swap(x[1][i], x[3][i]);
}
int judge(int x[4][4], int y[4][4]){
for (int i = 1; i <= 3; ++i)
for (int j = 1; j <= 3; ++j)
if (x[i][j] != y[i][j])
return 0;
return 1;
}
void solve(void) {
int x[4][4], y[4][4], temp[4][4];
for (int i = 1; i <= 3; ++i)
for (int j = 1; j <= 3; ++j)
cin >> x[i][j];
for (int i = 1; i <= 3; ++i)
for (int j = 1; j <= 3; ++j)
cin >> y[i][j];
A(x); if(judge(x, y)){ cout<<"A";return ; }
A(x); if(judge(x, y)){ cout<<"AA";return ; }
A(x); if(judge(x, y)){ cout<<"B";return ; } A(x);
C(x); if(judge(x, y)){ cout<<"C";return ; }
A(x); if(judge(x, y)){ cout<<"AC";return ; }
A(x); if(judge(x, y)){ cout<<"D";return ; }
A(x); if(judge(x, y)){ cout<<"AC";return ; } A(x);
D(x); if(judge(x, y)){ cout<<"D";return ; }
A(x); if(judge(x, y)){ cout<<"AD";return ; }
A(x); if(judge(x, y)){ cout<<"AB";return ; }
A(x); if(judge(x, y)){ cout<<"BD";return ; } A(x);
C(x); D(x); if(judge(x, y)){ cout<<"CD";return ; }
A(x); if(judge(x, y)){ cout<<"ACD";return ; }
A(x); if(judge(x, y)){ cout<<"AACD";return ;}
A(x); if(judge(x, y)){ cout<<"BCD";return ; }
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// cin >> t;
// while(t--)
solve();
return 0;
}