这种实现方法太蠢,实际上根本不需要自己算出坐标变换,只需要实现两个操作:旋转,以及翻转。然后叠加即可(参见ANALYSIS)
transform.cpp
/*
ID: america6
PROG: transform
LANG: C++11
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int n;
bool trans(const int& mode, const string& a, const string& b) {
//bool flag = true;
switch (mode) {
case 1: {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[j*n+n-i-1]) {
return false;
}
}
}
break;
}
case 2: {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[(n-i-1)*n+n-j-1]) {
return false;
}
}
}
break;
}
case 3: {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[(n-j-1)*n+i]) {
return false;
}
}
}
break;
}
case 4: {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[i*n+n-j-1]) {
return false;
}
}
}
break;
}
case 5: {
bool f1 = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[(n-j-1)*n+n-i-1]
/*&& a[i*n+j] != b[(n-i-1)*n+j]
&& a[i*n+j] != b[j*n+i]*/) {
f1 = false;
}
}
}
bool f2 = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[(n-i-1)*n+j]
/*a[i*n+j] != b[(n-j-1)*n+n-i-1]
&& a[i*n+j] != b[(n-i-1)*n+j]
&& a[i*n+j] != b[j*n+i]*/) {
f2 = false;
}
}
}
bool f3 = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[j*n+i]
/*a[i*n+j] != b[(n-j-1)*n+n-i-1]
&& a[i*n+j] != b[(n-i-1)*n+j]
&& a[i*n+j] != b[j*n+i]*/) {
f3 = false;
}
}
}
return f1 || f2 || f3;
}
case 6: {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i*n+j] != b[i*n+j]) {
return false;
}
}
}
break;
}
}
return true;
}
int main() {
ofstream fout ("transform.out");
ifstream fin ("transform.in");
fin >> n;
string before, after;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
char temp;
fin >> temp;
before.push_back(temp);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
char temp;
fin >> temp;
after.push_back(temp);
}
}
int mode = 7;
for (int i = 1; i <= 6; i++) {
if (trans(i, before, after) == true) {
mode = i;
break;
}
}
fout << mode << endl;
return 0;
}