当前位置:网站首页>數學知識:臺階-Nim遊戲—博弈論
數學知識:臺階-Nim遊戲—博弈論
2022-07-03 01:26:00 【奮鬥吧!騷年!】
題目:AcWing 892. 臺階-Nim遊戲
現在,有一個 n 級臺階的樓梯,每級臺階上都有若幹個石子,其中第 i 級臺階上有 ai 個石子(i≥1)。
兩比特玩家輪流操作,每次操作可以從任意一級臺階上拿若幹個石子放到下一級臺階中(不能不拿)。
已經拿到地面上的石子不能再拿,最後無法進行操作的人視為失敗。
問如果兩人都采用最優策略,先手是否必勝。
輸入格式
第一行包含整數 n。
第二行包含 n 個整數,其中第 i 個整數錶示第 i 級臺階上的石子數 ai。
輸出格式
如果先手方必勝,則輸出 Yes。
否則,輸出 No。
數據範圍
1≤n≤105,
1≤ai≤109
輸入樣例:
3
2 1 3
輸出樣例:
Yes
題目分析:
這一題與上一題做法差不多
a1^a3^a5…^an!=0則先手必贏
先手必贏策略:
如果拿偶數臺階,則將拿出來的放在下一臺階,則會保持奇數臺階保持不變。
如果拿奇數臺階,則异或不為0,則操作讓其异或變為0。
反之,如果异或為0,則後手贏。
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int res=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(i%2)res^=x;
}
if(res)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
边栏推荐
- Trois tâches principales: asynchrone, courrier et timing
- 【FPGA教程案例6】基于vivado核的双口RAM设计与实现
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
- 一位苦逼程序员的找工作经历
- 信息熵的基础
- Compare version number
- Basic concept and implementation of overcoming hash
- 软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
- Leetcode 2097 - Legal rearrangement of pairs
猜你喜欢
攻克哈希的基本概念与实现
Leetcode 2097 - Legal rearrangement of pairs
MySQL --- 数据库查询 - 基本查询
Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man
MySQL
机器学习术语
JDBC courses
Androd gradle's substitution of its use module dependency
每日一题之干草堆的移动
Top ten regular spot trading platforms 2022
随机推荐
Compare version number
Androd gradle's substitution of its use module dependency
leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
On Fibonacci sequence
MySQL --- 数据库查询 - 条件查询
按鍵精靈打怪學習-多線程後臺坐標識別
Swiftui component Encyclopedia: using scenekit and swiftui to build interactive 3D pie charts (tutorial with source code)
Is there a handling charge for spot gold investment
Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
【第29天】给定一个整数,请你求出它的因子数
数学知识:Nim游戏—博弈论
dotConnect for PostgreSQL数据提供程序
JS inheritance and prototype chain
【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
强化学习 Q-learning 实例详解
[untitled]
Leetcode 2097 - Legal rearrangement of pairs
Cut point of undirected graph
Button wizard play strange learning - go back to the city to buy medicine and add blood
Is there anything in common between spot gold and spot silver