hdu 4759 Poker Shuffle
2013-11-03 19:54
323 查看
读通题意应该要往二进制的方向去想,因为牌的个数是(1<<n)个的,
尝试发现每一次操作都是对数字的循环右移一位,如果是把奇数放到前面则还要异或(1<<n-1);
发现这个规律后,我们可以选循环右移再异或(而且可以异或上任何值,我们可以假设我们已经事先循环右移了n次);
枚举循环右移的次数,然后异或上一个值使它变成我们想要的值,因为 a ^ c = b - > a ^ b = c
这样我们这样比较所得到的c是否相同就可以了;
View Code
尝试发现每一次操作都是对数字的循环右移一位,如果是把奇数放到前面则还要异或(1<<n-1);
发现这个规律后,我们可以选循环右移再异或(而且可以异或上任何值,我们可以假设我们已经事先循环右移了n次);
枚举循环右移的次数,然后异或上一个值使它变成我们想要的值,因为 a ^ c = b - > a ^ b = c
这样我们这样比较所得到的c是否相同就可以了;
import java.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String[] arg) { Solve t = new Solve(); t.main(); } } class Solve{ int n; BigInteger right(BigInteger x) { BigInteger tp = x.and(BigInteger.valueOf(1)); return x.shiftRight(1).or(tp.shiftLeft(n-1)); } public void main(){ Scanner cin = new Scanner(System.in); int T = cin.nextInt(); int cas = 0; while (T-- != 0) { n = cin.nextInt(); BigInteger a = cin.nextBigInteger(); BigInteger x = cin.nextBigInteger(); BigInteger b = cin.nextBigInteger(); BigInteger y = cin.nextBigInteger(); BigInteger tp = BigInteger.valueOf(-1); a = a.add(tp); x = x.add(tp); b = b.add(tp); y = y.add(tp); int fg = 0; for (int i = 0; i < n; i++) { x = right(x); y = right(y); BigInteger ta = a.xor(x); BigInteger tb = b.xor(y); if (ta.compareTo(tb) == 0) { fg = 1; break; } } cas++; System.out.print("Case "+cas+": "); if (fg == 1) System.out.println("Yes"); else System.out.println("No"); } } }
View Code
相关文章推荐
- 大数模板 hdu 4759 Poker Shuffle
- hdu 4759 Poker Shuffle 二进制
- hdu 4759 Poker Shuffle(规律,大数,位)
- 二进制-hdu-4759-Poker Shuffle
- hdu 4759 - Poker Shuffle(巧妙二进制)
- 2013长春网赛1001 hdu 4759 Poker Shuffle
- hdu 4759 Poker Shuffle 进制(找规律)★
- hdu 4759 Poker Shuffle 进制(找规律)
- hdu 4759 大数+找规律 ***
- HDU 3336 解题报告
- HDU 2065
- hdu1232 畅通工程
- HDU 1066 Last non-zero Digit in N!
- hdu 1056
- hdu 2058 解题报告 - The sum problem
- hdu 1053 Entropy(哈夫曼编码)
- hdu 3948(后缀数组+RMQ)
- [HDU 3336]Count the String[kmp][DP]
- hdu-1018亚洲赛区现场赛的水题吧?
- hdu 1021 Fibonacci Again(水题)