F. Do Not Play Nim【GDUT 2022 grade Qualifying】

F. Do Not Play Nim

原题链接
image
image

题意

两人轮流取石头,要求后手每次取得石头数目不少于先手所取石头数目的总和,先手可以任意取

思路

由于每个人希望获胜,因此每次都会取数目最大的石头堆【假设堆数为M】里的所有石头。假设石头总数为N

  1. M==1,先手必胜
  2. M==2
    ① N == 2 后手必胜
    ② N > 2 先手必胜
  3. M > 2 先手必胜

因此只有一种情况是后手必胜的

代码

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
 
#define X first
#define Y second
 
typedef pair<int,int> pii;
typedef long long LL;
const char nl = '\n';
const int N = 1e6+10;
const int M = 2e5+10;
int n,m;
int a[M];
 
void solve(){
	cin >> n;
	for(int i = 1; i <= n; i ++ )cin >> a[i];
	if(n == 2 && a[1] == a[2])cout << "Bob" << nl;
	else cout << "Alice" << nl;
}
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
 
	int T;
	cin >> T;
	while(T --){
		solve();
	}
	//solve();
}
posted @ 2023-03-05 15:40  Keith-  阅读(21)  评论(0编辑  收藏  举报