当前位置:网站首页>數學知識:臺階-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;
}
边栏推荐
- Tp6 fast installation uses mongodb to add, delete, modify and check
- 异步、郵件、定時三大任務
- On Fibonacci sequence
- 【无标题】
- Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
- 2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
- Basic concept and implementation of overcoming hash
- What operations need attention in the spot gold investment market?
- Assets, vulnerabilities, threats and events of the four elements of safe operation
- Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
猜你喜欢

Excel removes the data after the decimal point and rounds the number

一比特苦逼程序員的找工作經曆

12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet

Work experience of a hard pressed programmer

Strongly connected components of digraph

Assets, vulnerabilities, threats and events of the four elements of safe operation

看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9

无向图的割点
![[C language] detailed explanation of pointer and array written test questions](/img/24/c2c372b5c435cbd6eb83ac34b68034.png)
[C language] detailed explanation of pointer and array written test questions

MySQL - database query - condition query
随机推荐
【无标题】
看疫情之下服装企业如何顺势而为
Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
Database SQL language 02 connection query
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
Embrace the safety concept of platform delivery
【FH-GFSK】FH-GFSK信号分析与盲解调研究
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
Trois tâches principales: asynchrone, courrier et timing
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
Arduino dy-sv17f automatic voice broadcast
[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge
MySQL
[自我管理]时间、精力与习惯管理
On Fibonacci sequence
Niu Ke swipes questions and clocks in
Makefile中wildcard、patsubst、notdir的含义
Key wizard play strange learning - front desk and Intranet send background verification code
【第29天】给定一个整数,请你求出它的因子数