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; }
相关文章推荐
- poj-2236-Wireless Network
- 46.BOOL / bool / Boolean / NSCFBoolean
- Codeforces Round #344 (Div. 2) Messager KMP的应用
- OnAccountsUpdateListener
- 图片编辑canvas
- Redis快速入门
- 【HTML5】DOCTYPE声明
- python中学习有待解决的问题
- 关于IList、IQueryable、IEnumerable与Func、Expression的关系2-详解
- C#之文件管理
- 数据挖掘-MATLAB下svm小例子
- openssl学习篇之base64编码、解码;md5 摘要;sha1摘要;3des加密,解密;rsa算法
- 蓝桥杯 小朋友排队 (树状数组好题)
- python--软件、模块相关安装问题
- 第三次作业(二)————————————程序阅读
- [Eclipse] - Return change set from outgoing to unresolved
- java中位运算的一点研究
- rsync+sersync实现文件实时同步
- 内存分配
- JavaScript 中的 String.prototype.match() 方法