读通题意应该要往二进制的方向去想,因为牌的个数是(1<<n)个的,
尝试发现每一次操作都是对数字的循环右移一位,如果是把奇数放到前面则还要异或(1<<n-1);
发现这个规律后,我们可以选循环右移再异或(而且可以异或上任何值,我们可以假设我们已经事先循环右移了n次);
枚举循环右移的次数,然后异或上一个值使它变成我们想要的值,因为 a ^ c = b - > a ^ b = c
这样我们这样比较所得到的c是否相同就可以了;
1 import java.util.*; 2 import java.math.*; 3 import java.io.*; 4 5 public class Main { 6 public static void main(String[] arg) { 7 Solve t = new Solve(); 8 t.main(); 9 } 10 } 11 class Solve{ 12 int n; 13 BigInteger right(BigInteger x) { 14 BigInteger tp = x.and(BigInteger.valueOf(1)); 15 return x.shiftRight(1).or(tp.shiftLeft(n-1)); 16 } 17 public void main(){ 18 Scanner cin = new Scanner(System.in); 19 int T = cin.nextInt(); 20 int cas = 0; 21 while (T-- != 0) { 22 n = cin.nextInt(); 23 BigInteger a = cin.nextBigInteger(); 24 BigInteger x = cin.nextBigInteger(); 25 BigInteger b = cin.nextBigInteger(); 26 BigInteger y = cin.nextBigInteger(); 27 BigInteger tp = BigInteger.valueOf(-1); 28 a = a.add(tp); 29 x = x.add(tp); 30 b = b.add(tp); 31 y = y.add(tp); 32 int fg = 0; 33 for (int i = 0; i < n; i++) { 34 x = right(x); 35 y = right(y); 36 BigInteger ta = a.xor(x); 37 BigInteger tb = b.xor(y); 38 if (ta.compareTo(tb) == 0) { 39 fg = 1; 40 break; 41 } 42 } 43 cas++; 44 System.out.print("Case "+cas+": "); 45 if (fg == 1) System.out.println("Yes"); 46 else System.out.println("No"); 47 } 48 49 } 50 51 }