Codeforces 705B.Spider Man

来源:互联网 发布:淘宝代销经营地址 编辑:程序博客网 时间:2024/05/16 09:03
B. Spider Man
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 least2 vertices (for example, x vertices) among all available cycles and replace it by two cycles withp andx - p vertices where1 ≤ 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 thei-th test he adds a cycle withai 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 integersa1, a2, ..., an (1 ≤ ai ≤ 109),i-th of them stands for the number of vertices in the cycle added before thei-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
31 2 3
Output
211
Input
51 1 5 1 1
Output
22222
Note

In the first sample test:

In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses.

In his second test, there's one cycle with 1 vertex and one with2. No one can make a move on the cycle with1 vertex. First player can replace the second cycle with two cycles of1 vertex and second player can't make any move and loses.

In his third test, cycles have 1, 2 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size1 and one with size2. Now cycles have1, 1, 2, 2 vertices. Second player's only move is to replace a cycle of size2 with2 cycles of size1. And cycles are1, 1, 1, 1, 2. First player replaces the last cycle with2 cycles with size1 and wins.

In the second sample test:

Having cycles of size 1 is like not having them (because no one can make a move on them).

In Peter's third test: There a cycle of size 5 (others don't matter). First player has two options: replace it with cycles of sizes1 and4 or 2 and 3.

  • If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player's only option to replace one of them with two cycles of size1. Second player does the same thing with the other cycle. First player can't make any move and loses.
  • If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes1 and2. Now only cycles with more than one vertex are two cycles of size2. As shown in previous case, with2 cycles of size 2 second player wins.

So, either way first player loses.



题意:俩人轮流分数字,先将所有的数字分成1为赢,玩家1赢输出1,否则输出2,每次都是玩家1先分!

(此题有毒,本人理解能力有限!读了半天依然没动!最后百度题意才晓得!!!55555)


思路:2 = 1+1,所有整除2的话就可以赢!所以谁先分2或2的倍数就肯定能赢。但是堆是依次增加的,所以当玩家1赢得本轮比赛后,下一堆数字来临时,应该是玩家2是先手(因为规则是谁最后分成1即为赢)所以此时的数字可以整数2或倍数,即为玩家2赢,玩家1则输,依次循环标记本轮几号玩家赢,然后判断满足条件即可!


代码:

import java.util.Scanner;public class d705B {public static void main(String[] args){read r = new read();while(r.getWhile()){int n = r.getValue();int[] a = new int[n];int flag = 1;//用于标记谁是先手for(int i=0;i<n;i++){a[i] = r.getValue();}for(int i=0;i<n;i++){if(flag == 1){//1是先手if(a[i] == 1){//不可分,所以1输了System.out.println("2");}else if(a[i] % 2 == 0){//可分,1赢System.out.println("1");flag = 2;//标记下一把2是先手,(因为1这把赢以为着他是最后一次分,所以到下一把2先手)}else{//其他1都输System.out.println("2");}}else{//2是先手,以下代码原理同上!if(a[i] == 1){System.out.println("1");}else if(a[i] % 2 == 0){System.out.println("2");flag = 1;}else{System.out.println("1");}}}}}}class read{private Scanner value;public read(){value = new Scanner(System.in);}public int getValue(){return value.nextInt();}public boolean getWhile(){return value.hasNext();}}


思路2:数字n要成1,需要n-1次,所以每堆数字-1求和判断奇偶即可,奇数:1赢      偶数 :   2赢

0 0
原创粉丝点击