您的位置:首页 > 其它

Codeforces 645A Amity Assessment【八数码】

2016-03-19 14:18 169 查看

题目链接:

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: