当前位置:网站首页>【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; } 边栏推荐
- Arduino_ STM development record
- MS office level II wrong question record [4]
- Decimal to binary
- Pointer to a two-dimensional array
- MySQL设置管理员密码无法生效的案例一则
- MFC custom string linked list
- C language judging big end and small end [consortium or pointer] big end and small end conversion
- MS office level II wrong question record [6]
- Matplotlib, set coordinate scale size, font / set legend size and font / set vertical and horizontal coordinate name, font and size
- I/o multiplexing - select/poll/epoll
猜你喜欢

JVM tuning

2022.5.30-6.5 AI行业周刊(第100期):三年时光

【LeetCode】-- 17. Letter combination of telephone number

Summary of classic interview questions

QT custom control library creation
![[analysis of STL source code] summary notes (6): Design of iterator and magical traits](/img/57/eaf02e880d205c5912f353609c9520.png)
[analysis of STL source code] summary notes (6): Design of iterator and magical traits

Seata的几种事务模式

Several transaction modes of Seata

2022 low voltage electrician test questions and online simulation test

Classification of MNIST datasets with keras
随机推荐
Android和iOS逆向分析/安全检测/渗透测试框架
Post-processing of ffmpeg miscellaneous notes
2022低压电工操作证考试题模拟考试平台操作
【CF#697 (Div. 3)】 A - Odd Divisor
Crmeb/v4.4 Standard Version open version mall source code applet official account h5+app mall source code
[analysis of STL source code] summary note (4): behind the scenes hero allocator
2022年熔化焊接与热切割考试练习题及答案
Education expert wangzhongze shared his experience for many years: family education is not a vassal
MFC custom string linked list
Interview question 02.06 Palindrome linked list
Summary of classic interview questions
Summary of written test questions of shopee 2021 autumn recruitment
Several transaction modes of Seata
CMAP of Matplotlib
【CF#262 (Div. 2)】 A. Vasya and Socks
JVM Learning record (7) - - class Loading Process and parent delegation Model
Seata的几种事务模式
Sqlzoo question brushing record-3
Use definite integral to calculate triangle area
JVM学习记录(七)——类加载过程与双亲委派模型