HDU3032-


,请谅解~

Nim or not Nim?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 960    Accepted Submission(s): 466

Problem Description

Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come
from the same heap.

Nim is usually played as a misere game, in which the player to take the last object loses. Nim can also be played as a normal play game, which means that the person who makes the last move (i.e., who takes the last object) wins. This is called normal play because
most games follow this convention, even though Nim usually does not.

Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. That is, each turn the player may either remove any number of objects from a heap or separate
a heap into two smaller ones, and the one who takes the last object wins.

Input

Input contains multiple test cases. The first line is an integer 1 ≤ T ≤ 100, the number of test cases. Each case begins with an integer N, indicating the number of the heaps, the next line contains N integers s[0], s[1], ...., s[N-1],
representing heaps with s[0], s[1], ..., s[N-1] objects respectively.(1 ≤ N ≤ 10^6, 1 ≤ S[i] ≤ 2^31 - 1)

Output

For each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes.

Sample Input

2
3
2 2 3
2
3 3

Sample Output

Alice
Bob

经典的NIM:Lasker‘s Nim
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

const int maxn = 1000000+10;
int n;
int num[maxn];

int main(){

    int ncase;
    cin >> ncase;
    while(ncase--){
        scanf("%d",&n);
        int ans = 0;
        for(int i = 0; i < n; i++) {
            scanf("%d",&num[i]);
            if(num[i]%4==3) num[i]++;
            else if(num[i]%4==0) num[i]--;
            ans ^= num[i];
        }
        if(ans!=0){
            printf("Alice\n");
        }else{
            printf("Bob\n");
        }

    }
    return 0;
}

HDU3032-

时间: 2024-08-25 10:09:31

HDU3032-的相关文章

【HDU3032】【Lasker&#39;s Nim(一种Nim游戏)】Nim or not Nim? Multi-SG博弈、打表

转载请注明出处:http://blog.csdn.net/vmurder/article/details/42652745 其实我就是觉得原创的访问量比未授权盗版多有点不爽233... 题意:n堆石子,每次可以从某堆中拿走若干,也可以把此堆分成两个非空堆,谁无法操作了谁输. 题解:首先我们可以打个SG函数来暴力出解,但是显然这会T. 但是不要害怕,我们打完以后发现了一个貌似对的规律: 对于所有的k >= 0,有 sg( 4k+1 ) = 4k+1: sg( 4k+2 ) = 4k+2: sg(

Nim or not Nim? hdu3032 SG值打表找规律

Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 858    Accepted Submission(s): 412 Problem Description Nim is a two-player mathematic game of strategy in which players take turns

hdu3032 Nim or not Nim?(SG函数)

Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1710    Accepted Submission(s): 845 Problem Description Nim is a two-player mathematic game of strategy in which players take tur

HBase-scan API 通过scan读取表中数据

直接贴代码啦 /** * * @param zkIp * @param zkPort * @param tablename * @param startRow 传null扫全表 * @param stopRow 已~结尾 * @throws Exception */ public static void scanTable(String zkIp,String zkPort,String tablename,String startRow,String stopRow) throws Excep

HDU-3032

Problem Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come

HDU3032 nim博弈

题目大意: 可以从某一堆中取任意个数,也可把一堆分成两个不为0的堆,直到某一方无法操作为输 因为是nim博弈,所以只要考虑一堆时候的sg值,把所有堆的sg值异或即可 很显然这里 0 是一个终止态 sg[0]=0; sg[1]=1 ; 2 的时候可分为 0 , 1 , (1,1) 3种情况,sg值分别为 0,1,0,所以sg[2]=2 3的时候可分为0,1,2,(1,2),sg值分别为0,1,2,3,所以sg[3]=4 而4的时候sg[4]=3 多试验可得sg(4k)=4k-1;sg(4k+1)=

Nim or not Nim?(hdu3032+SG函数)取走-分割游戏,经典

小k,终于忍不住了...正在笔记本上装win10,有点小激动. Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3032 Description Nim is a two-player mathematic game of strategy in which players take turns remov

HDU3032_NimOrNotNim解题报告

 HDU3032 Nim or not Nim 解题报告:思路与证明 胡明晓 Description Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. That is, each turn the player

ACdream 1112 Alice and Bob(素筛+博弈SG函数)

Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Practice ACdream 1112 Description Here  is Alice and Bob again ! Alice and Bob are playing a game. There are several numbers. First, Alice choose