当前位置:网站首页>【AtCoder2305】Decrementing(博弈)
【AtCoder2305】Decrementing(博弈)
2022-06-11 07:23:00 【CaptainHarryChen】
题意
黑板上有n个数,它们的最大公约数为1.于是A和B决定玩一个游戏,两个人轮流进行操作,A先手。
从黑板上的数选择一个不小于2的数,把这个数减去1,然后对于这n个数,除以他们的最大公约数.
当一个人无法操作时便输了。求先手是否必胜。
题解
定义状态1:有奇数个偶数,奇数至少一个
定义状态2:有偶数个偶数,且奇数个数≥2
定义状态3:有偶数个偶数,奇数一个
所有数都为1,为必败态,属于状态2
状态2,无论选哪一个数操作,gcd都不为偶数,操作后,偶数个数-1,只能转移到状态1
而状态1保证可以操作后转为状态2,所以状态2为必败态
状态3,如果选择偶数操作,转换为状态2,必败。选择奇数,继续递归求解。
代码
#include<cstdio> #include<algorithm> using namespace std; const int MAXN=100005; int n,A[MAXN]; bool solve() {
if(n==1) return false; int cnt[2]={
0,0}; for(int i=1;i<=n;i++) cnt[A[i]&1]++; if(cnt[0]&1) return true; if((cnt[0]&1)==0&&cnt[1]>=2) return false; int pos=-1; for(int i=1;i<=n&&pos==-1;i++) if(A[i]&1) pos=i; if(A[pos]==1) {
int sum=0; for(int i=1;i<=n;i++) sum^=(A[i]-1)&1; return sum; } A[pos]--; int g=A[1]; for(int i=2;i<=n;i++) g=__gcd(g,A[i]); for(int i=1;i<=n;i++) A[i]/=g; return solve()^1; } int main() {
scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&A[i]); if(solve()) puts("First"); else puts("Second"); return 0; } 边栏推荐
- P3811 [template] multiplicative inverse
- Create a form whose client area is 800 pixels by 600 pixels
- Android and IOS reverse analysis / security detection / penetration testing framework
- 2022 low voltage electrician operation certificate test question simulation test platform operation
- Arduino_ Esp32 development record
- MFC debugger OutputDebugString override
- MS office level II wrong question record [8]
- P3327 [sdoi2015] approximate sum (Mobius inversion + formula)
- Sdl-4 PCM playback
- 【CF#223 (Div. 2)】A. Sereja and Dima
猜你喜欢

一、SQLServer2008安裝(帶密碼)、創建數據庫、C#窗體項目測試

C language to write a calculator calculation logic

学 SQL 必须了解的10个高级概念

RTMP protocol

Raspberry pie builds a full-featured NAS server (07): manage your library & read as you please
![[STL source code analysis] summary notes (12): functors and adapters](/img/6d/a3a9cde2c8792579af7505c2226914.jpg)
[STL source code analysis] summary notes (12): functors and adapters

Installation de SQL Server 2008 (avec mot de passe), création d'une base de données, test de projet de formulaire C

Education expert wangzhongze solves students' problems with one move

Aiop introduction

Miscellany C language
随机推荐
Set center alignment
Pointer to a two-dimensional array
MFC custom string linked list
What is the difference between gaussdb for redis and redis?
QT 基于QScrollArea的界面嵌套移动
【CF#262 (Div. 2)】 A. Vasya and Socks
Qstring to hexadecimal qstring
[Oracle database] mammy tutorial day02 use of database management tool sqlplus
【CF#697 (Div. 3)】 A - Odd Divisor
Post-processing of ffmpeg miscellaneous notes
Notes on learning Es5 and ES6
[Oracle database] mammy tutorial day03 Sorting Query
Server parameter adjustment record
2022年熔化焊接与热切割考试练习题及答案
【CF#223 (Div. 2)】A. Sereja and Dima
2022.5.30-6.5 AI行业周刊(第100期):三年时光
【CodeForces1019E】Raining season(边分治+斜率优化)
Mistakes in Niuke JS exercise
Biological sequence intelligent analysis platform blog (1)
Ffmpeg extraction package format extracts AAC and customizes adtc header to realize arbitrary frame decoding