CodeForces 705B (训练水题)

时间:2023-03-09 17:21:09
CodeForces 705B (训练水题)

题目链接:http://codeforces.com/problemset/problem/705/B

CodeForces 705B (训练水题)

题意略解:

两个人玩游戏,解数字,一个数字可以被分成两个不同或相同的数字 (3可以解成 1 2),最小1不能再解

示例1:

第一把 当前1号玩家开始解数字 1,不能解, 则2号赢 输出2

第二把 当前数字为 1 2, 1号玩家直接对 2 进行解 解成 1 1,数字为 1 1 1,2号玩家无解,1号赢

第三把 当前数字为 1 2 3,一号玩家先对 2 解,解成 1 1,数字为 1 1 1 3,2号玩家只能对3 解,解成 1 1 1 1 2,1 player only process 2, ->1 1 1 1 1 1,

2 player can't process , so 1 player win.

解题思路:

这是一个递推问题,分析一个将数字拆成两个数的步数,1 -》0步,2-》1步, 3-》2步

然后将 步数 相加 偶数步则 2 赢,否则 1 赢。

Ac code:

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
int x[],sum=;
for(int i=; i<n; i++)
{
scanf("%d",&x[i]);
sum+=x[i]-;
if(sum%==)printf("2\n");
else printf("1\n");
}
}
return ;
}