D. Deleting Divisors(博弈,思维)

Posted goto_1600

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了D. Deleting Divisors(博弈,思维)相关的知识,希望对你有一定的参考价值。

链接
题意 :简要来说就是双方玩游戏,假设当前数为n,那么每次可以减去除了1和本身的因数,最后不能操作的话就输了。
思路:
也是个类似于sg函数打表找规律题,由于必胜态不可能是偶数,那么我们肯定尽量要让对方变成奇数,怎么操作呢?如果当前数是奇数,那么我方肯定输,当前数是偶数的话,如果含有除了2的质因子也是必赢,因为每次我们可以减奇数,让对方变成奇数,如果全含2的话,可以发现,如果当前数是2^i次,我们只能操作减去2的i-1次,因为减去其他,让对方变为偶数肯定是不行的,只要判断2的次幂是奇偶就行啦。
代码:

// Problem: D. Deleting Divisors
// Contest: Codeforces - Codeforces Round #726 (Div. 2)
// URL: https://codeforces.com/contest/1537/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
using namespace std;
int main()
{
	ios;
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		if(n%2)	cout<<"Bob"<<endl;
		else {
			int cnt=0;
			while(n%2==0)	cnt++,n/=2;
			if(n!=1)	 cout<<"Alice"<<endl;
			else
			{
				if(cnt&1)	cout<<"Bob"<<endl;
				else cout<<"Alice"<<endl;
			}
		}
	}
	
	return 0;
}



以上是关于D. Deleting Divisors(博弈,思维)的主要内容,如果未能解决你的问题,请参考以下文章

博弈论:倒腾思维D. Deleting Divisors——Codeforces Round #726 (Div. 2)

博弈论:倒腾思维D. Deleting Divisors——Codeforces Round #726 (Div. 2)

D. Almost All Divisors(思维)

每天一道博弈论之“The jar of divisors”

CF 666 (Div. 2) D. Stoned Game博弈论

CF 666 (Div. 2) D. Stoned Game博弈论