Code Forces 645A Amity Assessment

时间:2022-08-29 16:04:15

A. Amity Assessment

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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).

Examples

input

AB

XC

XB

AC

output

YES

input

AB

XC

AC

BX

output

NO

我直接暴力来的

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <map> using namespace std;
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int vis[5000];
struct Node
{
int a[2][2];
int s;
int posx;
int posy;
Node(){};
Node(int a[2][2],int s,int posx,int posy)
{
this->s=s;
this->posx=posx;
this->posy=posy;
memcpy(this->a,a,sizeof(this->a));
}
};
Node st,ed;
map<char,int>m; int kt(int a[2][2])
{
int num=0;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
num=num*10+a[i][j];
return num;
}
int bfs(Node st)
{
queue<Node>q;
q.push(st);
while(!q.empty())
{
Node term=q.front();
q.pop();
if(term.s==ed.s)
{
return 1;
} for(int i=0;i<4;i++)
{
int xx=term.posx+dir[i][0];
int yy=term.posy+dir[i][1];
if(xx<0||xx>=2||yy<0||yy>=2)
continue;
swap(term.a[term.posx][term.posy],term.a[xx][yy]);
int state=kt(term.a);
if(vis[state])
{
swap(term.a[term.posx][term.posy],term.a[xx][yy]);
continue;
}
vis[state]=1;
q.push(Node(term.a,state,xx,yy));
swap(term.a[term.posx][term.posy],term.a[xx][yy]);
}
}
return 0;
}
int main()
{
m['A']=1;m['B']=2;m['C']=3;m['X']=0;
char b1[2][2];
memset(vis,0,sizeof(vis));
for(int i=0;i<=1;i++)
scanf("%s",b1[i]);
for(int i=0;i<=1;i++)
for(int j=0;j<=1;j++)
{
st.a[i][j]=m[b1[i][j]];
if(b1[i][j]=='X')
st.posx=i,st.posy=j;
}
st.s=kt(st.a);
for(int i=0;i<=1;i++)
scanf("%s",b1[i]);
for(int i=0;i<=1;i++)
for(int j=0;j<=1;j++)
{
ed.a[i][j]=m[b1[i][j]];
if(b1[i][j]=='X')
ed.posx=i,ed.posy=j;
}
ed.s=kt(ed.a);
if(bfs(st))
printf("YES\n");
else
printf("NO\n");
return 0; }

Code Forces 645A Amity Assessment的更多相关文章

  1. CodeForces 645A Amity Assessment

    简单模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #incl ...

  2. Codeforces 645A Amity Assessment【八数码】

    题目链接: http://codeforces.com/problemset/problem/645/A 题意: 2*2的八数码问题 分析: 这题n为2,不需要搜索,直接判断字母排列顺序就好了. 注意 ...

  3. 思维题--code forces round&num; 551 div&period;2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  4. CROC 2016 - Elimination Round &lpar;Rated Unofficial Edition&rpar; A&period; Amity Assessment 水题

    A. Amity Assessment 题目连接: http://www.codeforces.com/contest/655/problem/A Description Bessie the cow ...

  5. codeforces 655A A&period; Amity Assessment&lpar;水题&rpar;

    题目链接: A. Amity Assessment time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  6. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  7. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  8. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  9. code forces 383 Arpa&&num;39&semi;s loud Owf and Mehrdad&&num;39&semi;s evil plan&lpar;有向图最小环&rpar;

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

随机推荐

  1. php课程---JavaScript与Jquery的区别

    使用Jquery必须在页面内引入一个Jquery包 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quot ...

  2. 编程式事务、XML配置事务、注解实现事务

    Spring2.0框架的事务处理有两大类: 1 编码式事务 , 这个不说. 2 声明式事务 , 就说这个. 声明式事务又有三种实现方法: 1 (第一种) 最早的方法,用TransactionProxy ...

  3. &period;NET 4&period;0中的泛型协变和反变

    转自:http://www.cnblogs.com/Ninputer/archive/2008/11/22/generic_covariant.html 随Visual Studio 2010 CTP ...

  4. 【BZOJ1042】【DP &plus; 容斥】&lbrack;HAOI2008&rsqb;硬币购物

    Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请问每次有多少种付款方法. Input 第一 ...

  5. 【&period;NET】电话号码打星号(隐藏部分)

    描述:支持多个电话: //隐藏部分内容,支持一个值有多个联系方式,用逗号隔开.//参数:value - 值,subIndex - 从第几位开始,subQty - 隐藏几位数 protected str ...

  6. Linux -- 项目部署

    一 . 负载均衡 负载均衡其实就是把其中一个服务器用做反向代理, 然后通过访问这个服务器实现负载均衡. 1.准备三台虚拟机 192.168.81.130 192.168.81.131 192.168. ...

  7. Practice&vert; 数组

    /* 从键盘确定班级的组号,在从键盘输入每一组的人数,并输入每一个学员的成绩,并求出,每一组的平均分, 全部的平均分,每一组的最高分,全部的最高分,并显示结果. */ class Test3{ pub ...

  8. 【转载】linux下升级npm以及node

    原文:http://blog.csdn.net/qq_16339527/article/details/73008708 npm升级 废话不多说,直接讲步骤.先从容易的开始,升级npm. npm这款包 ...

  9. day04-完整性约束

    完整性约束 关键字: not null 与 default unique primary auto_increment foreign key 1.介绍 约束条件与数据类型的宽度一样,都是可选参数作用 ...

  10. ConcurrentHashMap 源码阅读小结

    前言 每一次总结都意味着重新开始,同时也是为了更好的开始.ConcurrentHashMap 一直是我心中的痛.虽然不敢说完全读懂了,但也看了几个重要的方法,有不少我觉得比较重要的知识点. 然后呢,放 ...