hdu4759 Poker Shuffle 规律题
来源:互联网 发布:氯化钠的提纯实验数据 编辑:程序博客网 时间:2024/05/22 02:29
思路:把所有标号减1,这里要从二进制的角度来找规律,我们先考虑把单数牌放到最前面的情况。注意我们之后讨论的都是减1后的。
我们观察每个数值i在洗牌以后位置的变化
数值
0 1 10 11 100 101 110 111
位置1:
0 1 10 11 100 101 110 111
位置2(偶数在前):
0 100 1 101 10 110 11 111
位置2(奇数在前):
100 0 101 1 110 10 111 11
我们可以发现 做完(偶数在前)操作时, 每个数的位置的数值是跟操作之前的位置的数值是同构的,现在有(奇数在前)的操作,我们进一步发现,
选择任意两个数值x,y,把它们的位置的数值抑或以后的值val与操作之前的 这个数值也是同构的。
问题变为 判 操作后的val与原先的val是否同构。
import java.io.*;import java.util.*;import java.math.*;class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int cas = in.nextInt(); BigInteger one = BigInteger.ONE; BigInteger a, b, x, y; int n; for(int ca = 1; ca <= cas; ca++) { n = in.nextInt(); a = in.nextBigInteger().subtract(one); x = in.nextBigInteger().subtract(one); b = in.nextBigInteger().subtract(one); y = in.nextBigInteger().subtract(one); boolean ok = false; BigInteger bit = BigInteger.valueOf(1).shiftLeft(n-1); a = a.xor(b); x = x.xor(y); for(int i = 0; i < n; i++) { if(a.equals(x) == true) { ok = true; break; } boolean t = a.testBit(0); a = a.shiftRight(1); if(t == true) a = a.xor(bit); } System.out.print("Case "+ca+": "); if(ok == true) System.out.println("Yes"); else System.out.println("No"); } }}
- hdu4759 Poker Shuffle 规律题
- Hdu4759.Poker Shuffle
- hdu 4759 Poker Shuffle 进制(找规律)
- hdu 4759 Poker Shuffle 进制(找规律)★
- 二进制-hdu-4759-Poker Shuffle
- hdu 4759 - Poker Shuffle(巧妙二进制)
- 大数模板 hdu 4759 Poker Shuffle
- poker
- ZOJ1111:Poker Hands(模拟题)
- 【规律题】
- 规律题
- 规律题
- Shuffle
- shuffle
- 一道狗血的ACM题:Poker Hands
- UVa 131 The Psychic Poker Player (枚举&模拟好题)
- CF#318-C - Bear and Poker-大水题t
- Poker游戏?
- POJ 一 1573 Robot Motion
- 漫谈经典排序算法:一、从简单选择排序到堆排序的深度解析
- 工厂模式
- hdu 1698 - Just a Hook(线段树)
- 现代诗歌
- hdu4759 Poker Shuffle 规律题
- iphone的致命硬伤
- Tomcat配置详解(一)
- 三极管
- 详解android:scaleType属性
- Xcode5 After modifying system headers, please delete the module cache
- Vim学习指南
- SQL语句的两次执行问题
- opencv打开一幅图像