hdu 4759 Poker Shuffle 二进制
2013-10-01 10:59
246 查看
思路:主要是二进制的运用。
为了方便从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(此处是异或运算符)既可。
代码如下:
View Code
为了方便从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=1,n,tt; c=BigInteger.ONE; tt=cin.nextInt(); while(tt-->0){ 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=0;i<n;i++){ if(a.equals(x)){ flag=true; break; } if(a.testBit(0)){ a=a.shiftRight(1); a=a.setBit(n-1); }else a=a.shiftRight(1); } if(flag) System.out.println("Case "+t+": Yes"); else System.out.println("Case "+t+": No"); t++; } } }
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 - 5833 Zhu and 772002 二进制高斯消元
- HDU 4596 (Yet another end of the world)(二进制进位次数和)
- (HDU 1429)胜利大逃亡(续) BFS + 二进制状态压缩
- HDU 4825 Xor Sum(字典树&&二进制)
- hrbust 1231/hdu 3118 Arbiter【二进制枚举】好题
- HDU-5050 Divided Land (二进制求GCD)
- hdu 6166 Senior Pan(多源最短路径)(二进制划分集合)
- HDU-6166 Senior Pan - 2017 Multi-University Training Contest - Team 9(最短路+二进制乱搞)
- hdu5050.Divided Land (二进制求GCD)(Java大数随便搞)
- hdu 5661贪心二进制
- hdu 2844 Coins 多重背包模板题 ,二进制优化。据说是楼教主的男人八题之一
- HDU 5050 Divided Land (二进制上的最大公约数)