zcmu-2959(字符串找规律+注意内存范围)

问题 B: Amity Assessment

时间限制: 2 Sec  内存限制: 256 MB
提交: 51  解决: 17
[提交][状态][讨论版]

题目描述

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.

 

输入

 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 "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).

样例输入

AB

XC

XB

AC

样例输出

YES

提示

 

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

 

 

 

[提交][状态][讨论版]

题意:前两行每行输入2*2的已知矩阵a,后两行输入2*2的结果矩阵b,如果a能通过移动元素到空位置得到b,就输出“YES”,

否则输出“NO”。其中‘X'代表空位置。

思路:一开始想dfs模拟,后来发现种类太多,行不通。可以将矩阵拉直,变成abcx,如果延长就变成abcabc,结果矩阵可以视为bca,因为bca是abcabc的子串,所以输出“YES“。(要注意将数组开的大一点,否则过不去)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char a[10][10],b[10][10];
int main(void)
{
    string ss,s1;
    scanf("%s",a[0]);
    scanf("%s",a[1]);
    scanf("%s",b[0]);
    scanf("%s",b[1]);
    if(a[0][0]!='X') ss.push_back(a[0][0]);
    if(a[0][1]!='X') ss.push_back(a[0][1]);
    if(a[1][1]!='X') ss.push_back(a[1][1]);
    if(a[1][0]!='X') ss.push_back(a[1][0]);
    ss=ss+ss;
    if(b[0][0]!='X') s1.push_back(b[0][0]);
    if(b[0][1]!='X') s1.push_back(b[0][1]);
    if(b[1][1]!='X') s1.push_back(b[1][1]);
    if(b[1][0]!='X') s1.push_back(b[1][0]);
    int l=ss.size(),fg=0;
    for(int i=0;i<l-3;i++)
    {
        if(ss[i]==s1[0]&&ss[i+1]==s1[1]&&ss[i+2]==s1[2]) fg=1;
    }
    //cout<<ss<<" "<<s1<<endl;
    if(fg) 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、付费专栏及课程。

余额充值