POJ 3537 Crosses and Crosses SG函数
2016-07-18 09:03
337 查看
在1*n的格子里轮流划×,先划3个连续的×获胜,当在i这个位置划×之后,分成2部分:开始到i-3和i+2到结束。
package fd; import java.lang.reflect.Array; import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { static int[] sg = new int[2222]; static int SG(int n) { if(n <= 0) { return 0; } if(n <= 3) { return 1; } if(sg != -1) { return sg ; } Set<Integer> s = new HashSet<Integer>(); for(int i = 1; i<= n; i++) { s.add(SG(i-3)^SG(n-i-2)); } int res = 0; while(s.contains(res)) { res++; } return sg = res; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); Arrays.fill(sg, -1); while(sc.hasNext()) { int n = sc.nextInt(); System.out.println(SG(n) == 0 ? 2 : 1); } } }
相关文章推荐
- POJ 2082 Terrible Sets 单调栈
- POJ 3169 Layout 差分约束
- POJ 1742 Coins 多重背包
- POJ 1284 Primitive Roots 原根
- 调整数组顺序使奇数位于偶数前面 java
- Java DES加密
- 虽然每天都是自己一个人做饭菜
- 自定义组合控件
- 克隆已有节点
- Android WebView使用
- ListView中获取系统联系人
- Redis的pub/Sub(订阅与发布)在java中的实践
- java/设计原则
- overload(重载) override(覆盖) overwrite(重写)
- 8086汇编语言自学经验分享 U命令查看指定内存处内容翻译成的指令
- 8086汇编语言自学经验分享 T命令执行CS:IP所指内存的指令
- Linux文件属性及操作
- 《开心消消乐二》
- MySQL触发器
- 第2个100天