阶梯Nim博弈--Nim游戏进阶版

有一点难,首先题目看不太懂

 

 

阶梯Nim博弈--Nim游戏进阶版

 。。。。。。

样例:

2

3

1 2 3

8

1 5 6 7 9 12 14 17

public class Main{
    
    public static void main(String[] args) {
        //先不考虑按照题目的输入
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int shuju[] = new int[n];
        for(int i=0;i<n;i++) {
            shuju[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        int shuju2[] = new int[m];
        for(int i=0;i<m;i++) {
            shuju2[i] = sc.nextInt();
        }
        System.out.println(dfs(shuju));
        System.out.println(dfs(shuju2));
        
    }
    public static String dfs(int shuju[]) {
        int len = shuju.length;
        Arrays.sort(shuju);
        int res = 0;

       //奇数
        if((len&1)==1) {    //判断是奇数还是偶数
            for(int i=0;i<len;i+=2) {
                res ^=(i==0)?(shuju[0]-1):(shuju[i]-shuju[i-1]-1);
            }
        }else {
            for(int i=1;i<len;i+=2) {
                res ^=(shuju[i]-shuju[i-1]-1);
            }
        }
        if(res==0)
            return "Bob will win";
        else
            return "GG will win";
    }
}