SDNU_ACM_ICPC_2020_Winter_Practice_1st E

题目

Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.

Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p and x - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).

Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In the i-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?

Peter is pretty good at math, but now he asks you to help.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.

The second line contains n space separated integers a1, a2, …, an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.

Output
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.

Examples
Input
3
1 2 3
Output
2
1
1
Input
5
1 1 5 1 1
Output
2
2
2
2
2
大意:
n是n个测试样例,输入n个数。
假设其中一个数是x,那么要把他替换成p,p-x两个数,p是任意数(0<p<x),谁先把x替换成x个1,谁就赢了。

思路

可以理解为共n个回合,输出每个回合赢得玩家。
注意,假如上一回合的最后是玩家1成功拆分出所有的1,即1赢了,那么下一回合就该有玩家2先开始拆分。
简单说就是,输了拆分对象不变,赢了,那么需要进行拆分的对象变成另一个玩家。

首先,假若是1的话,不能拆分,也就意味着当前需要拆分的人输了。
假若x>1呢?
举例子,
2可以拆分1次(2->1,1)
3可以拆分2次(3->1,2 1,2->1,1,1)
4可以拆分3次 (4->1,3 1,3->1,1,2 1,1,2->1,1,1,1)或(4->2,2 2,2->1,1,2 1,1,2->1,1,1,1)
5可以拆分4次
。。。。。。
可以看出,x若为偶数,成功拆分次数为奇数
x若为奇数,成功拆分次数为偶数

拆分次数为奇数,则最开始拆分的人赢,但要注意,我们之前分析的,上一回合没有赢的人才会在下一回合先拆分,所以,赢的是上一回合输的人。则拆分次数为奇数(x为偶数),赢的对象改变
相同的,我们也可以分析出,拆分次数为偶数(x为奇数),赢的对象不变

AC代码

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n,sum=0;
    cin>>n;
    int ans[2]={2,1},p=0;
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x%2==0)
        {
            p++;
        }///拆分次数为奇数(x为偶数),赢的对象改变
        cout<<ans[p%2]<<endl;
    }
    return 0;
}
发布了46 篇原创文章 · 获赞 0 · 访问量 1161

猜你喜欢

转载自blog.csdn.net/weixin_45719073/article/details/104069279