Codeforces 645A Amity Assessment【八数码】

来源:互联网 发布:淘宝代理需要多少钱 编辑:程序博客网 时间:2024/05/21 09:40

题目链接:

http://codeforces.com/problemset/problem/645/A

题意:

2*2的八数码问题

分析:

这题n为2,不需要搜索,直接判断字母排列顺序就好了。
注意,如果n为奇数,直接看逆序数是否相同。

代码:

#include<iostream>#include<cstring>using namespace std;int f(string s1, string s2){    int posa, posc;    swap(s2[0], s2[1]);    string ns = s1 + s2;    int a = 0;    for(int i = 0; i < 4; i++){        if(ns[i] == 'X') continue;        if(ns[i] == 'A') posa = a;        if(ns[i] == 'C')  posc = a;        a++;    }    if(posc == posa + 1 || posa == 2 && posc == 0)        return 1;    return 0;}int main (void){    string a1, a2, b1, b2;    cin>>a1>>a2>>b1>>b2;    if(f(a1, a2) == f(b1, b2)) cout<<"YES"<<endl;    else cout<<"NO"<<endl;}
0 0
原创粉丝点击