首页 > 其他 > 详细

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

时间:2015-11-26 13:04:41      阅读:377      评论:0      收藏:0      [点我收藏+]

题目链接: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

 

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

原文:http://www.cnblogs.com/andyqsmart/p/4997315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!