Codeforces 645A Amity Assessment 【暴力】

题目链接:Codeforces 645A Amity Assessment

题意:给你两个 22 矩阵,每次你可以将 X 与周围的ABC互换,问你这两个矩阵是否可以相互转化。

AC 代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define PI acos(-1.0)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define fi first
#define se second
#define ll o<<1
#define rr o<<1|1
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 2*1e5 + 10;
const int pN = 1e6;// <= 10^7
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
char a[2][2], b[2][2];
bool judge() {
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            if(a[i][j] != b[i][j])
                return false;
        }
    }
    return true;
}
bool Check() {
    int sx, sy;
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            if(b[i][j] == 'X') {
                sx = i;
                sy = j;
            }
        }
    }
    if(judge()) return true; int nx, ny;
    for(int i = 0; i < 12; i++) {
        if(sx == 0) {
            if(sy == 0) {
                nx = 0; ny = 1;
            }
            else {
                nx = 1; ny = 1;
            }
        }
        else {
            if(sy == 0) {
                nx = ny = 0;
            }
            else {
                nx = 1; ny = 0;
            }
        }
        swap(b[sx][sy], b[nx][ny]);
        sx = nx; sy = ny;
        if(judge()) return true;
    }
    return false;
}
int main()
{
    for(int i = 0; i < 2; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < 2; i++) {
        cin >> b[i];
    }
    bool flag = Check();
    printf(flag ? "YES\n" : "NO\n");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值