CodeForce 1373 - B. 01 Game - 简单思维题

题目传送门:B. 01 Game

题目大意

给定一个01串,两个人轮流操作,每次只能删除两个相邻并且不同的两个数(也就是只能删除“01”或者“10”,删完后剩下的又会连起来变成相邻的),最后不能再操作的输,先手赢输出"DA",否则输出"NET"

思路

每次要删除也只能删除一个0和一个1,并且很容易想到最后只会剩下全是0或者全是1,那么不管怎么操作,操作总数num都是固定不变为01串里0的个数和1的个数中的最小值,即min(num0, num1)

那么如果num为奇数那么先手赢,反之,后手赢

代码

#include 
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair PII;
typedef pair pll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
ll qpow(ll base, ll n){ll ans = 1; while (n){if (n & 1) ans = ans * base % mod; base = base * base % mod; n >>= 1;} return ans;}
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
char s[110];
int main()
{
	int t;
	cin >> t;
	while (t --){
		scanf("%s", s + 1);
		int n = strlen(s + 1);
		int num = 0;
		for (int i = 1; i <= n; ++ i){
			if (s[i] == '1') ++ num;
		}
		int x = min(num, n - num);
		if (x & 1) printf("DA\n");
		else printf("NET\n");
	}
	return 0;
}

 

你可能感兴趣的:(CodeForce 1373 - B. 01 Game - 简单思维题)