列表

详情


NC222871. GoodGame,GG

描述

Alice and Bob are playing a game. Initially there are  positive numbers, the -th number is a_i. In one turn, Alice can choose an odd number and divide it into two positive numbers, or delete a number equals to 1. Bob can choose an even number and divide it into two positive numbers. Two players move in turns, and Alice move first. In one's turn, if he or she can't move, he or she lose the game. If two player move optimally, please find out who the winner is.

You need to answer  queries.

输入描述

First line contains one integer  ().

In each query:

First line contains one integer  ().

Second line contains  integers, the -th integer is a_i ().

The sum of  is less than .

输出描述

In each query, print Aliceif Alice is the winner, print Bob otherwise.

示例1

输入:

4
3
2 4 6
2
1 2
3
1 1 4
4
2 2 3 6

输出:

Bob
Alice
Alice
Bob

说明:

In first query, there are no odd number, Alice can not make a move, so Bob wins.
In second query, Alice can delete 1_{}, the list becomes [2]_{}. Bob can divide 2_{} into 1,1_{}, the list becomes [1,1]_{}. Then, Alice can delete 1_{}, the list becomes [1]_{}. Now Bob can't make a move, so Alice wins.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python3 解法, 执行用时: 101ms, 内存消耗: 16700K, 提交时间: 2021-07-15 15:29:54

a = int(input())
for i in range(a):
    cccc=0
    con=0
    b = int(input())
    lis = list(map(int,input().split()))
    for h in lis:
        if h%2 == 1:
            con = con+(h+1)//2
        else:
            cccc = cccc+(h//2-1)
    if (con>cccc):
        print("Alice")
    else:
        print("Bob")

C++ 解法, 执行用时: 13ms, 内存消耗: 396K, 提交时间: 2022-05-21 13:51:56

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t,n,x;
	cin>>t;
	while(t--){
		long long s1=0,s2=0;
		scanf("%d",&n);
		while(n--){
			scanf("%d",&x);
			if(x&1) s1+=x/2+1;
			else s2+=x/2-1;
		}
		puts(s1>s2?"Alice":"Bob");
	}
}

上一题