思路:主要是二进制的运用。

为了方便从0开始,首先看下右移一下,高位异或1的规律:(可以从右往左一列一列看)

000(0) -> 100(4) -> 110(6) -> 111(7) -> 011(3) -> 001(1) -> 000(0)

001(1) -> 000(0) -> 100(4) -> 110(6) -> 111(7) -> 011(3) -> 001(1)

010(2) -> 101(5) -> 010(2) -> 101(5) -> 010(2) -> 101(5) -> 010(2)

011(3) -> 001(1) -> 000(0) -> 100(4) -> 110(6) -> 111(7) -> 011(3)

100(4) -> 110(6) -> 111(7) -> 011(3) -> 001(1) -> 000(0) -> 100(4)

101(5) -> 010(2) -> 101(5) -> 010(2) -> 101(5) -> 010(2) -> 101(5)

110(6) -> 111(7) -> 011(3) -> 001(1) -> 000(0) -> 100(4) -> 110(6)

111(7) -> 011(3) -> 001(1) -> 000(0) -> 100(4) -> 110(6) -> 111(7)

每次洗牌的时候,奇数在后偶数在前时,只需右移一下;奇数在前偶数在后时,只需右移一下,高位亦或1.

而且每层的任意2个数异或的结果相同。

对于给定的n,a,b,x,y;只需判断a^b==x^y(此处是异或运算符)既可。

代码如下:

 import java.math.*;
import java.util.*;
public class Main {
public static void main(String arg[]){
BigInteger a,b,c,x,y;
Scanner cin=new Scanner(System.in);
int t=,n,tt;
c=BigInteger.ONE;
tt=cin.nextInt();
while(tt-->){
n=cin.nextInt();
a=cin.nextBigInteger();a=a.subtract(c);
x=cin.nextBigInteger();x=x.subtract(c);
b=cin.nextBigInteger();b=b.subtract(c);
y=cin.nextBigInteger();y=y.subtract(c);
a=a.xor(b);
x=x.xor(y);
boolean flag=false;
for(int i=;i<n;i++){
if(a.equals(x)){
flag=true;
break;
}
if(a.testBit()){
a=a.shiftRight();
a=a.setBit(n-);
}else a=a.shiftRight();
}
if(flag) System.out.println("Case "+t+": Yes");
else System.out.println("Case "+t+": No");
t++;
}
}
}

最新文章

  1. SQL批量添加主键脚本
  2. java开源网站
  3. Web 软件测试 Checklist 应用系列,第 1 部分: 数据输入
  4. 第二百四十七天 how can I 坚持
  5. easyui源码翻译1.32--ValidateBox(验证框)
  6. [LeetCode OJ] Symmetric Tree
  7. Ruby设计模式透析之 —— 适配器(Adapter)
  8. Struts2(四)——页面相关内容
  9. mybatis的延迟加载
  10. 递归一个List&lt;T&gt;,可自己根据需要改造为通用型。
  11. eclipse 开发web 项目,使用gradle 需要安装的插件
  12. Python函数之递归函数
  13. 手机网页制作教程META标签你知道多少?【转+加】
  14. [leetcode]41. First Missing Positive第一个未出现的正数
  15. vue使用路由跳转到上一页
  16. spark快速开发之scala基础之1 数据类型与容器
  17. oracle建存储过程
  18. invalid request block size: 4542 (max 4096)...skip引起的Nginx 502 Bad Geteway
  19. vs2015中的数据库架构对比工具(New Schema Comparison)
  20. $_cookie的使用

热门文章

  1. 2天驾驭DIV+CSS (实战篇)(转)
  2. OSGi 对软件复杂度的影响
  3. 初识java之Mina(一)
  4. 000 VS2013 c++ 框架
  5. MATLAB GUI程序设计中使文本框接收多行输入的方法
  6. cocos游戏的真正入口,用C++实现的demo版本
  7. N!大整数阶乘问题
  8. java 顺序表
  9. Careercup - Google面试题 - 5692127791022080
  10. STL容器的适用情况