ACM学习历程—UESTC 1215 Secrete Master Plan(矩阵旋转)(2015CCPC A)

题目链接:http://acm.uestc.edu.cn/#/problem/show/1215

题目大意就是问一个2*2的矩阵能否通过旋转得到另一个。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#define LL long long

using namespace std;

struct Matrix
{
    int v[2][2];

    void get()
    {
        for (int i = 0; i < 2; ++i)
            for (int j = 0; j < 2; ++j)
                scanf("%d", &v[i][j]);
    }

    void turn()
    {
        swap(v[0][0], v[0][1]);
        swap(v[0][0], v[1][1]);
        swap(v[0][0], v[1][0]);
    }

    bool operator==(const Matrix x) const
    {
        for (int i = 0; i < 2; ++i)
            for (int j = 0; j < 2; ++j)
                if (v[i][j] != x.v[i][j])
                    return false;
        return true;
    }
}a, b;

void input()
{
    a.get();
    b.get();
    bool flag = false;
    for (int i = 0; i < 4; ++i)
    {
        b.turn();
        if (a == b)
        {
            flag = true;
            break;
        }
    }
    if (flag) printf("POSSIBLE
");
    else printf("IMPOSSIBLE
");
}

int main()
{
    //freopen("test.in", "r", stdin);
    int T;
    scanf("%d", &T);
    for (int times = 1; times <= T; ++times)
    {
        printf("Case #%d: ", times);
        input();
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/andyqsmart/p/4997315.html