题意:给你\(n\)堆石子玩尼姆博弈,每堆石子可以是\(a_i\)也可以是\(b_i\),选择概率相等且每堆选择相互独立,求先手必胜(异或不为0)的概率

首先需要找出一种优雅的策略表示方法(利用异或的思想)

我们需要处理的是\(c_i=a_i \ xor \ b_i\)的线性基,然后用\(S\)代表\(a_i\)的整体异或,那么$S \ xor \ \((\)c_i\(的任意组合)即可表示原问题的选择策略
那么原问题首先转换为\)c_i\(是否可以凑出\)S$

剩下的我在代码中已经注释

PS.窝的天CF才A题就这么可怕的吗

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int MAXN = 5e5+11;
const double EPS = 1e-7;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 10086;
unsigned int SEED = 17;
const ll INF = 1ll<<60;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll b[66];
int cal(int n,ll a[]){
memset(b,0,sizeof b);
int cnt=0;
rep(i,1,n){
rrep(j,62,0){
if(a[i]>>j&1){
if(b[j]) a[i]^=b[j];
else{
b[j]=a[i];
rrep(k,j-1,0) if(b[k]&&(b[j]>>k&1))b[j]^=b[k];
rep(k,j+1,62) if(b[k]>>j&1) b[k]^=b[j];
break;
}
}
}
}
rep(i,0,62) if(b[i]) cnt++;
return cnt;
}
ll A[MAXN],B[MAXN],C[MAXN],n;
int main(){
while(cin>>n){
rep(i,1,n){
A[i]=read();
B[i]=read();
}
ll S=0;
rep(i,1,n) S^=A[i],C[i]=A[i]^B[i];
int cnt=cal(n,C);
rep(i,0,62) if(S>>i&1) S^=b[i];
//注意如果i位没有别瞎异或,相当于构造时的插入但不更新的操作
if(S){//不在线性基中
printf("1/1\n");
}else{
ll ans=1ll<<cnt; //线性基的所有可能
printf("%lld/%lld\n",ans-1,ans); //把唯一存在的异或为S的剔除便是胜率
}
}
return 0;
}

Codeforces - 662A 思路巧妙的异或的更多相关文章

  1. CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

    As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...

  2. Codeforces Round #539 (Div. 2) 异或 + dp

    https://codeforces.com/contest/1113/problem/C 题意 一个n个数字的数组a[],求有多少对l,r满足\(sum[l,mid]=sum[mid+1,r]\), ...

  3. 【题解】 Codeforces 662A Gambling Nim (线性基)

    662A,戳我戳我 Solution: 我们先取\(ans=a[1] \bigoplus a[2] \bigoplus ... \bigoplus a[n]\),然后我们定义\(c[i]=a[i] \ ...

  4. CodeForces.1174D.EhabandtheExpectedXORProblem(构造前缀异或和数组)

    题目链接 这道题比赛的时候没做出来,赛后补题的时候发现其实可以构造一个前缀异或和数组,然后根据初始化的第一个值进行填数,但是作为菜鸡的我虽然坚信自己的想法是正确的却想了很久也没有能够构造出来所谓的前缀 ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. POJ 2828 Buy Tickets 线段树 倒序插入 节点空位预留(思路巧妙)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19725   Accepted: 9756 Desc ...

  7. CodeForces - 348A Mafia (巧妙二分)

    传送门: http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory li ...

  8. Codeforces 1054D Changing Array 贪心+异或和

    题意 给一个长度为\(n\)的位数为\(k\)的整数数列\(a\),一次操作可将任意\(a_i\)取反,问经过任意次操作后最多有多少个区间异或和不为\(0\) 分析 求出前缀异或和,区间异或和为\(0 ...

  9. Codeforces 251D - Two Sets(异或方程组)

    题面传送门 题意: 你有一个可重集 \(S=\{a_1,a_2,\dots,a_n\}\),你要把它划分成两个可重集 \(S_1,S_2\) 使得 \(S\) 中每个元素都恰好属于 \(S_1\) 与 ...

随机推荐

  1. c语言实践打印字母三角形

    效果如下: int main(void) { char ch = 'A';//当前要打印的字符 ;//每行要打印字符的个数 ; i < ; i++,count++) { ; j < cou ...

  2. 清除Vs2010的工作区影射关系的缓存信息的文件夹路径

    C:/Users/Administrator/AppData/Local/Microsoft/Team Foundation/3.0/Cache

  3. DELPHI XE5 UP2 运行IOS 遇到 Wrapper init failed: (null)问题的解决办法

    一.问题表现: 在MAC OSX(10.9.2)上安装了比较新的XCODE5.1 和COMMAND LINE TOOLS 在DELPHI XE5 UP2上放了一个按钮,输出到MAC OSX上,出现: ...

  4. C# 中关于汉字与16进制转换的代码

    /// <summary> /// 从汉字转换到16进制 /// </summary> /// <param name="s"></par ...

  5. MQ入门总结(一)消息队列概念和使用场景

    一.消息队列 消息即是信息的载体.为了让消息发送者和消息接收者都能够明白消息所承载的信息(消息发送者需要知道如何构造消息:消息接收者需要知道如何解析消息),它们就需要按照一种统一的格式描述消息,这种统 ...

  6. Service Fabric 用 Powershell 部署应用到本地

    前置说明 安装 Service Fabric SDK,会在本机 C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\Servic ...

  7. vs2010远程调试断点无效问题

    ps:本人按照下面的方式设置成功,个人感觉写的也比较清楚 来源:http://www.cnblogs.com/OpenCoder/archive/2010/02/17/1668983.html   v ...

  8. Mybatis-generator逆向工程

    $.Mybatis-generator介绍 MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为所有版本的MyBatis以及版本2.2.0之 ...

  9. 《C#多线程编程实战》2.5 AutoResetEvent

    这个有点像是缩小版的mutex 还是很好理解的 相对mutex 使用的范围可能比较小一点. class Program { static AutoResetEvent work = new AutoR ...

  10. c++实验2 顺序存储线性表

    线性表顺序存储 实现了动态数组的增删改查  前驱后继  A=AUB 动态数组右移 (1)顺序表存储结构的定义(类的声明): class SeqList { protected: DataType *l ...