Yet Another Game of Stones ZOJ - 3964 (博弈)

C++开发基础之掌握常用的三种异步编程模型 以上是三种常见的C++异步编程模型,每种模型都有其适用的场景和特点。根据具体需求,你可以选择合适的模型来进行异步编程。 阅读详情

Alice and Bob are playing yet another game of stones. The rules of this game are as follow:

The game starts with n piles of stones indexed from 1 to n. The i-th pile contains ai stones and a special constraint indicated as bi.
The players make their moves alternatively. The allowable moves for the two players are different.
An allowable move of Bob is considered as removal of some positive number of stones from a pile.
An allowable move of Alice is also considered as removal of some positive number of stones from a pile, but is limited by the constraint bi of that pile.
If bi = 0, there are no constraints.
If bi = 1, Alice can only remove some odd number of stones from that pile.
If bi = 2, Alice can only remove some even number of stones from that pile.
Please note that there are no constraints on Bob.
The player who is unable to make an allowable move loses.
Alice is always the first to make a move. Do you know who will win the game if they both play optimally?

Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1 ≤ n ≤ 105), indicating the number of piles.

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 109), indicating the number of stones in each pile.

The third line of each test case contains n integers b1, b2, …, bn (0 ≤ bi ≤ 2), indicating the special constraint of each pile.

It is guaranteed that the sum of n over all test cases does not exceed 106.

We kindly remind you that this problem contains large I/O file, so it’s recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.

Output
For each test case, output “Alice” (without the quotes) if Alice will win the game. Otherwise, output “Bob” (without the quotes).

Sample Input
3
2
4 1
1 0
1
3
2
1
1
2
Sample Output
Alice
Bob
Bob
**思路:**nim博弈的变形问题。
代码:

#include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cmath>

using namespace std;
int a[100005];
int b[100005];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int countt=0;
        bool sign=false;
        int x;
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
            scanf("%d",a+i);
        for(int i=0;i<n;i++)
            scanf("%d",b+i);
        for(int i=0;i<n;i++)
        {
            if(a[i]%2&&b[i]==2)
                sign=true;
            if((a[i]>1&&b[i]==1)||(a[i]%2==0&&b[i]==2))
            {
                countt++;
                if(a[i]%2==0&&b[i]==1)
                    a[i]=1;
                else
                    a[i]=0;
            }
        }
        if(sign||countt>1)
        {
            cout<<"Bob"<<endl;
            continue;
        }
        int ans=0;
        for(int i=0;i<n;i++)
            ans^=a[i];
        if(countt==0)
            cout<<(ans?"Alice":"Bob")<<endl;
        else
            cout<<(ans==0?"Alice":"Bob")<<endl;
    }
    return 0;
}


【RT-DETR实战】RT-DETR实战手记(200):端侧实时目标检测,下一步往哪儿走? 昨天深夜调一个模型部署,在树莓派4B上跑RT-DETR-nano,帧率死活卡在8FPS上不去。量化也做了,算子也优化了,内存对齐也检查了,可就是离实时检测的底线还差一截。盯着终端里跳动的数字,突然意识到——我们可能正在接近当前技术路径的瓶颈。端侧实时目标检测的下一个突破口,恐怕不在现有框架的修修补补里。 阅读详情

相关推荐

SurfaceControlViewHost使用介绍

可以看到,主要用途:是把一个进程的View显示到另外一个进程里面。

chadm.xiang 1287

ZOJ 3964 Yet Another Game of Stones(博弈论)

题意: n堆石子。B每次在一堆取正数个。A取石子的数量受堆的限制。 堆类型是0:每次取正数个。 堆类型是1:每次取奇数个。 堆类型是2:每次取偶数个。 输出必胜的人。 题解: 与经典的nim博弈只差在A取个别石子有限制。那么首先考虑A取石子有限制的那几堆。 1.ai是奇数,bi=2。A必定取不完,那么最后肯定会剩下一个情景是:只有一堆是1,其他都是0。要么此时A

851

BambuStudio学习笔记:GCode 类

关键成员解析 核心配置组件 状态跟踪系统 功能模块集成 核心方法剖析 主输出管道 实现多阶段处理: 分层处理流程: 实现智能路径规划: 关键特性: 实现模板故障检测: 采用三级流水线: 支持扩展类型: 实现多通道输出: 采用: 实现: 支持: 支持模块化编译: 典型流程: 实现功能:

zzzkk2009的专栏 933

ZOJ_3964 Yet Another Game of Stones(博弈论)

Yet Another Game of Stones Time Limit: 1000 ms Memory Limit: 65536 KB Problem Description Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts w...

sigh_的博客 359

优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信

优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信今天开始会陆续介绍一些优秀的开源项目,项目基本都是和FPGA或HDL相关的。对于一些找工作或者急需项目经验的人来说,这些项目...

OpenFPGA的博客 8117

【Matlab】matlab代码实现sph溃坝模拟

本文介绍了一个基于MATLAB的SPH溃坝模拟实现。代码使用平滑粒子流体动力学方法,通过建立1000个随机分布的粒子,计算粒子间的相互作用力来模拟流体运动。模拟过程包括初始化参数、粒子创建、密度压力更新、速度位置计算以及可视化展示。核心算法采用poly6Kernel和spikyKernelGradient函数处理粒子间作用力。该示例为二维简化模型,仅包含基本物理参数和计算流程,实际应用需进一步优化扩展。

unber的博客 207

Yet Another Game of Stones

Yet Another Game of Stones Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts with n piles of stones indexed from 1 to n. The i-th pile conta

素宇的博客 609

深度学习实战35-图卷积神经网络GCN模型的搭建与应用

大家好,我是微学AI,今天给大家介绍一下深度学习实战35-图卷积神经网络GCN模型的搭建与应用,GCN是一种用于处理图结构数据的深度学习模型,它可以捕捉节点之间的拓扑关系和局部特征,并进行图级别的预测和分类任务。下面将介绍如何搭建并应用GCN模型。

微学AI的博客 2226

2017浙江省赛:Yet Another Game of Stones(尼姆变形)

Yet Another Game of Stones Time Limit: 1 Second      Memory Limit: 65536 KB Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts with

加载中... 1851

Transformer 在自动驾驶中的应用:深度对比特斯拉(Tesla)、小鹏(XNet)、华为(ADS 2.0)在 Transformer 架构应用上的异同

自动驾驶汽车是当前人工智能和机器学习领域的热点研究方向之一。其核心技术之一就是基于深度学习的感知和决策系统。在感知系统中,目标检测和跟踪、语义分割、场景理解等计算机视觉任务至关重要。而在决策系统中,规划和控制模块需要对当前状态进行建模并做出相应的决策。近年来,Transformer模型在自然语言处理领域取得了突破性进展,并逐步被应用到计算机视觉等其他领域。相比于传统的卷积神经网络和循环神经网络,Transformer模型具有建模长距离依赖关系的能力,可以更好地捕捉输入序列中的全局信息。

AI天才研究院 864

Cilium动手实验室: 精通之旅---1.Getting Started with Cilium

我们需要在 HTTP 层的第 7 层实施策略,以限制允许 tiefighter 调用的确切 API,以及不允许调用哪些 API。上仅需要的 API 资源的访问,从而为微服务之间的通信实施“最低权限”安全方法。船只上进行匹配,因此我们需要在该标签上进行匹配,此外,我们必须确保来自带有标签。为了模拟我们的连接测试,我们将使用 curl 执行简单的 API 调用。在我们立即开始更改策略之前,让我们考虑一下相应的网络策略应该是什么样子。的规则,该规则将通过 L3-L4 策略对死星的访问限制为仅帝国船只。

Q先生 1126

Yet Another Game of Stones---ZOJ Problem 3964

Yet Another Game of Stones Time Limit: 1 Second      Memory Limit: 65536 KB Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts with n

Big大鸟的博客 538

量化交易 米筐 案例:市值因子选股策略

案例:市值因子的选股策略 1.结果 获得超额收益 年化 49% 2. 从股票中选择市值小的股票 选定财务数据筛选 进行每日调仓(多因子选股调仓 周期频率会小一些) 3. 代码 估值有关指标 # 在沪深300股票中,选出市值比较小的10只股票 # 在这个方法中编写任何的初始化逻辑。context对象将会在你的算法策略的任何方法之间做传递。 def init(context): # 沪深300组合 stocks = index_components('000300.XSHG') # 沪深3

廷益_飞鸟的博客 2313

ZOJ 3964Yet Another Game of Stones 扩展尼姆博弈

ZOJ 3964Yet Another Game of Stones 扩展尼姆博弈题意思路Code 传送门: 题意 给n堆石头,每堆石头有a个数量和b性质。Alice和Bob玩游戏,每次只能在一堆中取任意多个石头。给n堆石头,每堆石头有a个数量和b性质。Alice和Bob玩游戏,每次只能在一堆中取任意多个石头。给n堆石头,每堆石头有a个数量和b性质。Alice和Bob玩游戏,每次只能在一堆中取任意多个石头。 b=0,Alice随便取。b=0,Alice随便取。b=0,Alice随便取。 b=1,Alice

狙击美佐的博客 231

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

ZOJ 3964 Yet Another Game of Stones (博弈)

题意:题意跟普通的nim博弈差不多  就是一位选手取的时候 加了一个限制条件 思路:         1.全部b[i]=0 那么 这个就是Al先手的NIM博弈 2.有多个b[i]>=1&&a[i]>1的情况 ,BO肯定会破环这几堆 让 AL不能取这堆 那么AL肯定会输。 接下来就是b[i]=1 同时a[i]=1时这个跟普通也一样, 当a[i]>1的个数为1 时, b[i]=1,a[i]

一切顺其自然 604

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

ZOJ 3964 Yet Another Game of Stones (博弈)

Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains ai stones and a special co

DorMOUSENone的博客 2579

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

ZOJ - 3964 Yet Another Game of Stones 博弈

Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains ai stones and a special ...

还我笑颜 352

ZOJ 3964 Yet Another Game of Stones(Nim博弈 待整理)

Yet Another Game of Stones Time Limit: 1 Second      Memory Limit: 65536 KB Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts with n

AI蜗牛之家 1284

ZOj 3964Yet Another Game of Stones(nim博弈)

Yet Another Game of Stones Time Limit: 1 Second      Memory Limit: 65536 KB Alice and Bob are playing yet another game of stones. The rules of this game are as follow: The game starts with n 

qq_37164003的博客 451

ZOJ-3964 Yet Another Game of Stones

Yet Another Game of Stones 题意: Alice 和 Bob 在进行取石子游戏, 现在一共有n堆石子, 每堆石头有ai个, 然后每堆石头有一个bi属性, 如果bi == 0, Alice取这堆石头就没有限制, 如果bi == 1 那么Alice对这堆石子一次只能取奇数个, 如果bi == 2那么Alice 对这堆石头一次只能取奇数个, 所有石头堆对于Bob来说说...

dengpangbu3703的博客 237

zoj 3964 - Yet Another Game of Stones

zoj 3964 - Yet Another Game of Stones // 2017zjpc 传送门 题意: 有n堆石子,每堆有一个限制0,1,2,限制只对Alice生效,分别表示没有限制,只能取奇数个,只能取偶数个,Alice先手,问她是否有必胜策略 思路: 是nim博弈上面加限制, 当没有限制->裸nim博弈:当异或和为0时先手必败,否则必胜;因为对B没有限制所以其实当异或为0就必败 当异或不为零,当B取偶数的时候A势必要取一个偶数使得回到异或不为零的情况,即留给B异或为0的情况;同理当B取

juraws的博客 234

ZOJ 3964 Yet Another Game of Stones Nim游戏变种

ZOJ3964 解题思路 此题的题意比较容易理解,可以简单的看着 Nim 博弈的变种。但问题在于 Alice 对第 i 堆石子的取法必须根据bi确定。所以如果这个问题能够归结到正常的 Nim 博弈(取石子问题),则很容易解决。 考虑特判存在bi=1或bi=2的情况: 如果存在第 i 堆石子,其ai为奇数且bi=2,则 Bob 必胜(Alice 在最优策略下无法取完该...

weixin_30325071的博客 178

Yet Another Game of Stones ZOJ - 3964

const int maxn = 1e6+100; int A[maxn]; int B[maxn]; int n,T; bool solve(){ scanf(&amp;quot;%d&amp;quot;,&amp;amp;amp;n); int sum = 0; int c1 = 0,c2 =0; rep(i,0,n) scanf(&amp;quot;%d&amp;quot;,&amp;amp;a

海边拾贝,沧海一粟 317

Yet Another Game of Stones(博弈论)

题目链接:题目 题意: n堆石子。B每次在一堆取正数个。A取石子的数量受堆的限制。 堆类型是0:每次取正数个。 堆类型是1:每次取奇数个。 堆类型是2:每次取偶数个。 输出必胜的人。 题解: 与经典的nim博弈只差在A取个别石子有限制。那么首先考虑A取石子有限制的那几堆。 1.ai是奇数,bi=2。A必定取不完,那么最后肯定会剩下一个情景是:只有一堆是1,其他都是0。要么此时A取,要么此时B取。无论如何A都输。 2.ai是偶数,bi=2。A一定要在第一次就全取完这一堆,否则B可以把这一.

weixin_43870697的博客 400

Codeforces Round #399:E. Game of Stones

E. Game of Stones time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Sam has been teaching Jon the Game of Sto

加载中... 1596

Codeforces 768E Game of Stones

NIM游戏改编,每堆石头同一种操作不能超过两次。 可以用SG[i][2^i-1]推出所有状态,复杂度是O(n*n*2^n)。 所以用记忆化搜索,当第一维状态为num时,第二维2^(num-1)前的所有1都可以去掉,因为那些点不会再被取到了。 代码: #include using namespace std; typedef long long ll; typedef pair P

Tooc0ld 690
上一篇: Accumulation Degree POJ - 3585 (树形dp)(二次扫描和换根法)
下一篇: Naptime POJ - 2228(环形dp处理)
coldfresh
博客等级 码龄10年 107粉丝 405原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值