POJ 3537 crosses and crosses SG functions

Source: Internet
Author: User
Tags arrays
In 1*n's lattice, the x is rotated, the 3 consecutive X wins, and after the position x is divided into 2 parts: start to I-3 and i+2 to the end.
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[n]! =-1) {
			return sg[n];
		}
		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[n] = 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);}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.