東華大學2020年程序設計競賽(同步賽)F A Simple GameF A Simple Game

比賽時看錯題了。。看出每次只能選擇一個串,當時想這不是公平組合遊戲水題嘛。。

直接SG函數一搞就行:

顯然全0先手必敗。

兩個操作:1操作是改變1數量的奇偶,2操作並不能改變奇偶(因爲2操作變成1,我再把1變回去,相當於沒有這一步操作)

所以剛開始一個串,1的個數是奇數,則先手必勝即 SG=1 否則先手必敗SG=0。

然後SG異或起來即可。。

但其實這一題是每次任選多個串。。

那其實也很簡單,只要剛開始存在一個串使得SG[i]=1  我先手把所有SG=1的變成SG=0. 那麼後手一定必敗。

否則,剛開始全部SG=0,我先手一定必敗。

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M =2e3+7;
char s[M];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int t;
  	cin>>t;
  	while(t--)
  	{
  		int n;
  		cin>>n;
  		int tp=0;
  		for(int i=1;i<=n;i++)
  		{
  			cin>>s;
			int sm=0;
  			int l=strlen(s); 
  			for(int j=0;j<l;j++)
  			{
  				if(s[j]=='1')
  					sm++;
			}
			if(sm&1)tp++;
		}
		if(tp)cout<<"sdzNB"<<endl;
		else cout<<"kgNB"<<endl;
	}
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章