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

来源:牛客网

筱玛爱游戏

时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 524288K,其他语言1048576K

64bit IO Format: %lld

题目描述

筱玛是一个热爱游戏的好筱玛。最近,筱玛和马爷在玩这样一种游戏:

首先,桌面上一共有

n

n个数。

两个人轮流从桌面上取走一个数,并把这个数放入集合中。

如果在某次操作结束后,集合中存在一个异或和为

0

0的非空子集,那么进行这次操作的人输。

如果全部取完,则最后操作的人赢。

筱玛和马爷都聪明绝顶,他们都会按照最优策略进行游戏。

马爷作为筱玛的爷爷,决定让筱玛选择先手还是后手。

筱玛为了稳操胜券,想提前知道对于当前的游戏,是先手必胜还是后手必胜。

筱玛想考考你,让你帮他解决这个问题。

输入描述:

输入共两行。

第一行一个整数

n

n,表示桌面上一共有n个数字。

第二行读入

n

n个数,表示桌面上每个数的数值。

输出描述:

输出"First"或"Second"(不包括引号)表示先手赢或后手赢。

示例1

输入

复制

3

1 2 3

输出

复制

Second

备注:

对于100%的数据,

n



10

5

n≤105,数值大小



2

61

≤261。

题意:



思路:



子集异或和不为0这恰好是线性基的性质。

那么我们把数组构造一个线性基,算出能插入到线性基里的个数,

如果是基数那么是先手赢,否则是后手赢。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ struct LB {
ll d[63], p[63];
int cnt, mx;
LB() {
memset(d, 0, sizeof(d));
memset(p, 0, sizeof(p));
cnt = 0, mx = 63;
}
void init() {
memset(d, 0, sizeof(d));
memset(p, 0, sizeof(p));
}
int add(ll val) {
/*插入时判断之前是否有数会与val异或得0,判第k小时如果有为0的情况,k要减一*/
for (int i = mx - 1; i >= 0; i--) {
if (val & (1LL << i)) {
if (!d[i]) {
d[i] = val;
return 1;
}
val ^= d[i];
}
}
return 0;
}
bool query(ll val) { // 查询val这个数是否存在
for (int i = mx - 1; i >= 0; i--) {
if (val & (1LL << i)) {
if (!d[i]) return 0;
val ^= d[i];
}
}
return 1;
}
ll query_max(ll val) {
ll ret = val;
for (int i = mx - 1; i >= 0; i--) if ((ret ^ d[i]) > ret) ret ^= d[i];
return ret;
}
ll query_min() {
for (int i = 0; i < mx; i++) if (d[i]) return d[i];
return 0;
}
void rebuild() {//消元,保存到p数组
cnt = 0;
for (int i = 0; i < mx; i++) {
for (int j = 0; j < i; j ++ )
if (d[i] & (1LL << j)) d[i] ^= d[j];
}
for (int i = 0; i < mx; i++) if (d[i]) p[cnt++] = d[i];
}
ll query_kth(ll k) { //使用前需要rebuild
ll ret = 0;
if (k >= (1LL << cnt)) return -1;
for (int i = cnt - 1; i >= 0; i--) if (k & (1LL << i)) ret ^= p[i];
return ret;
}
ll find(ll x) { //找x是第几大的数,需保证x一定在
ll ret = 0, c = 0;
for (int i = 0; i < mx; i++) {
if (d[i]) {
if (x >> i & 1) ret += (1LL << c);
c++;
}
}
return ret;
}
LB operator+(const LB & _A)const { //合并
LB ret = *this;
for (int i = mx - 1; i >= 0; i--) if (_A.d[i]) ret.add(_A.d[i]);
return ret;
}
};
LB base=LB(); int main()
{
//freopen("D:\common_text\code_stream\in.txt","r",stdin);
//freopen("D:\common_text\code_stream\out.txt","w",stdout); gbtb;
int n;
cin>>n;
int ans=0;
repd(i,1,n)
{
ll x;
cin>>x;
ans^=base.add(x);
}
if(ans)
cout<<"First"<<endl;
else
cout<<"Second"<<endl;
return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

牛客练习赛49 E 筱玛爱游戏 (线性基+博弈)的更多相关文章

  1. 牛客练习赛49 B 筱玛爱阅读 (状压DP,子集生成)

    链接:https://ac.nowcoder.com/acm/contest/946/B 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262875K,其他语言5257 ...

  2. 牛客练习赛B题 筱玛的排列(找递推规律)

    链接:https://ac.nowcoder.com/acm/contest/342/B来源:牛客网 筱玛的排列 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语 ...

  3. 牛客练习赛 A题 筱玛的快乐

    链接:https://ac.nowcoder.com/acm/contest/342/A来源:牛客网 筱玛的快乐 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语 ...

  4. 2019年牛客多校第一场 H题XOR 线性基

    题目链接 传送门 题意 求\(n\)个数中子集内所有数异或为\(0\)的子集大小之和. 思路 对于子集大小我们不好维护,因此我们可以转换思路变成求每个数的贡献. 首先我们将所有数的线性基的基底\(b\ ...

  5. 2019 牛客暑期多校 第一场 H XOR (线性基)

    题目:https://ac.nowcoder.com/acm/contest/881/H 题意:求一个集合内所有子集异或和为0的长度之和 思路:首先集合内异或和,这是线性基的一个明显标志,然后我们不管 ...

  6. 牛客练习赛53 A 超越学姐爱字符串 (DP)

    牛客练习赛53 超越学姐爱字符串 链接:https://ac.nowcoder.com/acm/contest/1114/A来源:牛客网 超越学姐非常喜欢自己的名字,以至于英文字母她只喜欢" ...

  7. 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D

    目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...

  8. 牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 逻辑,博弈 B

    牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 https://ac.nowcoder.com/acm/contest/218/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...

  9. 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A

    牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...

随机推荐

  1. ubuntu16虚拟机迁移/移动/复制后无法上网

    修改grub配置 如果没有网卡,需要配置 sudo vi /etc/default/grub 将 GRUB_CMDLINE_LINUX="" 修改为 GRUB_CMDLINE_LI ...

  2. learning webrtc 使用node.js

    第二章 有使用node.js创建静态服务器的步骤 不过不够详细 下面以Windows为例 1.到官方网站下载安装包 然后安装 2.用管理员权限启动命令行 3.命令行窗口执行npm config set ...

  3. 阶段3 1.Mybatis_09.Mybatis的多表操作_8 mybatis多对多操作-查询角色获取角色下所属用户信息

    一个角色对应多个用户 生成getter和setter 查看两个表的数据 中间表定义了谁有角色,谁没有角色 根据中间表的关系,最终查询出来的列表的数据样子.这需要两个左外链接才能实现功能. 第一个左外链 ...

  4. add_prefix()函数

    对于series,是给索引列加前缀. 对于Dataframe,是给列名加前缀. 参考:https://www.cjavapy.com/article/276/

  5. 正则表达式——Unicode 属性

      每一个 Unicode 字符,除了有 Code Point 与之对应外,还具体其他属性,在正则表达式中常用到三种 Unicode 属性: Unicode Property.Unicode Scri ...

  6. C# Hook 方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  7. 20191110 Spring Boot官方文档学习(4.1)

    4. Spring Boot功能 4.1.Spring应用 便捷的启动方式: public static void main(String[] args) { SpringApplication.ru ...

  8. axios入门使用

    vue项目中axios的基本使用和简单封装 axios中文文档官网 http://www.axios-js.com/docs/ 一:不封装直接使用 npm install axios 在main.js ...

  9. 如何在centos7中显示/etc/目录下以非字母开头,后面跟了一个字母及其它任意字符的文件或目录

    ls /etc |grep "^[^[:alpha:]][[:alpha:]].*"

  10. springboot + mybaits + oracle 项目

    1.pom设置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...