求 助 !
查看原帖
求 助 !
1436267
I_Love_Codm楼主2024/11/22 21:04
#include <iostream>
#include <vector>
using namespace std;
int n, pos;

bool equ(vector<vector<char>> from, vector<vector<char>> to) {
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) if(from[i][j] != to[i][j]) return false;
    return true;
}

void turn(vector<vector<char>> &vec) {
    vector<vector<char>> result(vec.size(), vector<char>(vec.size()));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) result[j][n - i - 1] = vec[i][j];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) vec[i][j] = result[i][j];
}

void reverse_vec(vector<vector<char>> &vec) {
    vector<vector<char>> result(vec.size(), vector<char>(vec.size()));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) result[n - i - 1][j] = vec[i][j];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) vec[i][j] = result[i][j];
}

int main() {
    cin >> n;
    vector<vector<char>> from(n, vector<char>(n)), sum(n, vector<char>(n)), to(n, vector<char>(n));
    vector<vector<bool>> vis(n, vector<bool>(n, false));

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) cin >> from[i][j], sum[i][j] = from[i][j];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) cin >> to[i][j];


    while(++pos < 4) {
        turn(sum);
        if(equ(sum, to)) {
            cout << pos;
            return 0;
        }
    }

    turn(sum);
    reverse_vec(sum);
    if(equ(sum, to)) {
        cout << pos;
        return 0;
    }

    while(++pos < 8) {
        turn(sum);
        if(equ(sum, to)) {
            cout << 5;
            return 0;
        }
    }

    cout << (equ(from, to)? 6: 7);
    return 0;
}

样例6在Dev上是对的,提交就是错的

2024/11/22 21:04
加载中...