令$f_{i}$(一个集合)表示当第$i$步开始时第0方必胜当且仅当$x\in f_{i}$,初始$f_{n+1}=\{0\}$

当$p_{i}=0$时,$f_{i}=\{x|x\in f_{i+1}或(x\oplus a_{i})\in f_{i+1}\}$;当$p_{i}=1$,$f_{i}=\{x|x\in f_{i+1}且(x\oplus a_{i})\in f_{i+1}\}$

归纳$f_{i}$具有以下性质:若$x,y\in f_{i}$,则$(x\oplus y)\in f_{i}$,如果只有$p_{i}=0$显然满足此性质,考虑当$p_{i}=1$时,对$a_{i}$是否存在于$f_{i+1}$中分类讨论:

1.若$a_{i}\in f_{i+1}$,根据此性质,则有$f_{i}=f_{i+1}$

2.若$a_{i}\notin f_{i+1}$,同样根据此性质,若$(x\oplus a_{i})\in f_{i+1}$,则$a_{i}\in f_{i+1}$,与假设矛盾,因此$f_{i}=\emptyset$

这个性质类似于线性基,因此用线性基来维护$f_{i}$即可,时间复杂度为$o(tn\log_{2}a_{i})$

 1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 205
4 #define ll long long
5 int t,n,ans;
6 ll a[N],w[N];
7 char s[N];
8 void add(ll k){
9 for(int i=59;i>=0;i--)
10 if (k&(1LL<<i)){
11 if (!w[i])w[i]=k;
12 k^=w[i];
13 }
14 }
15 bool check(ll k){
16 for(int i=59;i>=0;i--)
17 if (k&(1LL<<i)){
18 if (!w[i])return 0;
19 k^=w[i];
20 }
21 return 1;
22 }
23 int main(){
24 scanf("%d",&t);
25 while (t--){
26 scanf("%d",&n);
27 for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
28 scanf("%s",s+1);
29 memset(w,0,sizeof(w));
30 ans=0;
31 for(int i=n;i;i--)
32 if (s[i]=='0')add(a[i]);
33 else{
34 if (!check(a[i])){
35 ans=1;
36 break;
37 }
38 }
39 printf("%d\n",ans);
40 }
41 }

[atAGC045A]Xor Battle的更多相关文章

  1. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. BZOJ 2115 【Wc2011】 Xor

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

  5. xor和gates的专杀脚本

    前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...

  6. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  7. Xor && 线性基练习

    #include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...

  8. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  9. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

随机推荐

  1. MyBatis概念和”安装“

    MyBatis概念 MyBatis的前身就是iBatis,本是apache的一个开源项目,2010年这个项目由apahce sofeware foundation 迁移到了google code,并且 ...

  2. opencv中的exp32f函数

    exp32f opencv的exp函数和cmath的exp函数在精度上存在一定差异,通过查找源码,发现了这么一段实现.代码如下: 点击查看代码 #define EXPTAB_SCALE 6 #defi ...

  3. C 编译预处理和宏

    前置知识 0x00 cmd编译运行程序 https://blog.csdn.net/WWIandMC/article/details/106265734 0x01 --save-temps gcc m ...

  4. Java(27)集合二List

    作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15228435.html 博客主页:https://www.cnblogs.com/testero ...

  5. python使用Django框架开发简单项目

    一. (1)使用idea生成一个python项目,安装Django框架: pip install django==1.8.2 (2)初始化项目: django-admin startproject x ...

  6. 2021.10.18考试总结[NOIP模拟76]

    T1 洛希极限 不难发现每个点肯定是被它上一行或上一列的点转移.可以预处理出每个点上一行,上一列最远的能转移到它的点,然后单调队列优化. 预处理稍显ex.可以用并查集维护一个链表,记录当前点之后第一个 ...

  7. 震惊,hzoi的分差竟然折磨大,活到爆!

    众所周知,hzoi的分差非常"大",那么究竟有多大呢?最近,一位外国小哥开发出了hzoi的分差竟然折磨大,活到爆!的方法,这究竟是怎么一回事呢?快和小编一起来看看吧- 竟然1分就可 ...

  8. STM32的串口通信

    本篇文章主要讲解一个在开发过程中经常使用到的一个外设---串口. 串口是绝大多数 MCU 中不可或缺的一个外设,同时也是我们开发中经常使用的一种调试手段,所以在STM32的学习中,串口的配置使用也是必 ...

  9. Machine learning (8-Neural Networks: Representation)

    1.Non-linear Hypotheses 2.Neurons and the Brain 从某种意义上来说,如果我们能找出大脑的学习算法,然后在计算机上执行大脑学习算法或与之相似的算法,也许这将 ...

  10. Java RMI学习与解读(二)

    Java RMI学习与解读(二) 写在前面 接上篇文章,这篇主要是跟着看下整个RMI过程中的源码并对其做简单的分析 RMI源码分析 还是先回顾下RMI流程: 创建远程对象接口(RemoteInterf ...