题目链接: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\n");
    else printf("IMPOSSIBLE\n");
}

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

相关文章:

  • 2021-12-03
  • 2021-12-04
  • 2022-01-27
  • 2021-09-09
  • 2022-12-23
  • 2021-05-16
猜你喜欢
  • 2021-07-31
  • 2021-05-24
  • 2021-06-25
  • 2021-11-14
  • 2021-06-17
  • 2021-05-21
  • 2021-06-07
相关资源
相似解决方案