ZCMU-2959-Amity Assessment

Description

Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2×2 grid and three tiles labeled ‘A’, ‘B’, and ‘C’. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
在这里插入图片描述
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.

Input

The first two lines of the input consist of a 2×2 grid describing the initial configuration of Bessie’s puzzle. The next two lines contain a 2×2 grid describing the initial configuration of Elsie’s puzzle. The positions of the tiles are labeled ‘A’, ‘B’, and ‘C’, while the empty cell is labeled ‘X’. It’s guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.

Output

Output “YES”(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print “NO” (without quotes).

Sample Input

AB
XC
XB
AC

Sample Output

YES

HINT

The solution to the sample is described by the image. All Bessie needs to do is slide her ‘A’ tile down.

一开始觉得挺水的吧,但事实是想了很久,emmmm,其实想明白确实挺水的,2*2的方格,只能逆时针或顺时针转,但其实两种转法是一样的,所以只要模拟顺时针转或逆时针转,然后每转一次就比较一次,如果直至转到和初始状态(第二个方格)一样,就说明不能达成目标方格(第一个方格)。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))

char a[3][3];
char b[3][3];
char c[5];
char d[5];

int jud()
{
    int p = 1;
    for(int i = 0; i < 3; i++){
        if(c[i]!=d[i]){
            p = 0;
            break;
        }
    }
    return p;
}
int main()
{
    for(int i = 0; i < 2; i++) scanf("%s", a[i]);
    for(int i = 0; i < 2; i++) scanf("%s", b[i]);
    int k1 = 0, k2 = 0;
    for(int i = 0; i < 2; i++){
        if(i==0){
            for(int j = 0; j < 2; j++){
                if(a[i][j]!='X') c[k1++] = a[i][j];
                if(b[i][j]!='X') d[k2++] = b[i][j];
            }
        }else{
            for(int j = 1; j >= 0; j--){
                if(a[i][j]!='X') c[k1++] = a[i][j];
                if(b[i][j]!='X') d[k2++] = b[i][j];
            }
        }
    }
    //for(int i = 0; i < 3; i++) cout << c[i] << " " << d[i] << endl;
    int flag = 1;
    int cnt = 0;
    while(jud()==0){
        char ss = d[0];
        d[0] = d[1];
        d[1] = d[2];
        d[2] = ss;
        cnt++;
        if(cnt>3){
            flag = 0;
            break;
        }
    }
    //for(int i = 0; i < 3; i++) cout << c[i] << " " << d[i] << endl;
    if(flag){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值