牛客练习赛49 E. 筱玛爱游戏

链接

https://ac.nowcoder.com/acm/contest/946/E

题意

n个数,两人轮流操作,每次操作为从取走一个数放入集合。

  • 当放入后集合内存在一个异或和为 $0$ 的非空子集时,进行这次操作的人输;
  • 全部取完,最后操作的人赢。

问先手必胜还是后手必胜。

思路

保证集合内不存在异或和为 $0$ 的非空子集就是求这 $n$ 个数的最大线性无关组。

用线性基求秩。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef double DB;
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
// head
const int N=100;
int tot;
LL d[N];
bool add(LL x) { // 插入
for(int i=62;~i;i--) if((x>>i)&1) {
if(!d[i]) {d[i]=x;return true;}
x^=d[i];
}
return false;
}
void calc() { // 统计线性基元素数量
tot=0;
for(int i=0;i<63;i++) if(d[i]) ++tot;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;cin>>n;
for(int i=1;i<=n;i++) {
LL x;cin>>x;
add(x);
}
calc();
cout<<(tot&1?"First":"Second")<<'\n';
return 0;
}