【打CF,学算法——二星级】Codeforces 705B Spider Man (简单博弈)

【CF简介】

题目链接:CF 705B

题面:

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 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

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 with
2. No one can make a move on the cycle with
1 vertex. First player can replace the second cycle with two cycles of
1 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 size
1 and one with size 2. Now cycles have
1, 1,
2, 2 vertices. Second player‘s only move is to replace a cycle of size
2 with 2 cycles of size
1. And cycles are 1,
1, 1, 1,
2. First player replaces the last cycle with 2 cycles with size
1 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 sizes
1 and 4 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 size
    1. 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 sizes
    1 and 2. Now only cycles with more than one vertex are two cycles of size
    2. As shown in previous case, with
    2 cycles of size 2 second player wins.

So, either way first player loses.

题意:

博弈游戏,一堆数,可以拆成两堆非空的,所有堆都不能拆,则为输。每次不断加入一个新堆,问在当前所有堆的情况下的输赢状况。

解题:

因为一个数字n,可以拆的次数为固定的n-1次,故而只要统计全部的可操作次数,看总和的奇偶性即可。

代码:

#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
int main()
{
	int n;
	LL sum=0,tmp;
	cin>>n;
	while(n--)
	{
		cin>>tmp;
		sum+=tmp-1;
		if(sum%2)
		  cout<<1<<endl;
        else
          cout<<2<<endl;

	}
	return 0;
}
时间: 2024-10-29 19:12:23

【打CF,学算法——二星级】Codeforces 705B Spider Man (简单博弈)的相关文章

Codeforces 15C Industrial Nim 简单博弈

题目链接:点击打开链接 题意: 给定n 下面n行,每行2个数u v 表示有v堆石子:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先根据Nim的博弈结论 把所有数都异或一下,看结果是0还是非0 而这里因为数字太多所以想优化 那么其实对于一个序列 u, u+1, u+2 ···· 显然 {4,5} {,6,7}, {8,9} 这样2个一组的异或结果就是1 那么只需要把序列分组,分成{偶数,奇数} 然后Y一下.. #include<stdio.h> #include<

【打CF,学算法——二星级】Codeforces 699B - One Bomb (技巧)

[CF简介] 题目链接:CF 699B 题面: B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a description of a depot. It is a rectangular checkered field of n?×?m size. Each cell in a

【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/B 题面: B. Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Gerald bought two very rare paintings at the Sotheby's a

【打CF,学算法——二星级】CodeForces 237B Young Table (构造)

[CF简介] 提交链接:CF 237B 题面: B. Young Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci

【打CF,学算法——二星级】Codeforces 703B Mishka and trip (统计)

[CF简介] 题目链接:CF 703B 题面: A - Mishka and trip Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u SubmitStatusPracticeCodeForces 703B Description Little Mishka is a great traveller and she visited many countries. After thinking

【打CF,学算法——二星级】CF 520B Two Buttons

[CF简单介绍] 提交链接:Two Buttons 题面: B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has found a strange device. On the front panel of a device there are: a red button, a blu

【模拟】Codeforces 705B Spider Man

题目链接: http://codeforces.com/problemset/problem/705/B 题目大意: 两个人玩游戏,总共N个数,分别求前I(I=1 2 3...n)个数时游戏的获胜者是谁. 游戏规则是可以把一个大于2的数拆成任意大小的两个数,1不能拆,问谁先不能拆谁输.先手输输出2,后手输输出1. 题目思路: [模拟] 很容易想到把一个数拆成两个数,不管怎么拆最后都会被拆成k个1,所以只要判断前I个数的奇偶就行了.(如果是1直接跳过,答案和上一把一样,因为1不能拆) 1 // 2

CodeForces 705B Spider Man (水题)

题意:给定 n 个数,表示不同的环,然后把环拆成全是1,每次只能拆成两个,问你有多少次. 析:也不难,反正都要变成1,所以把所有的数都减1,再求和即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include &

1169: 零起点学算法76——绝对公正的裁判

1169: 零起点学算法76--绝对公正的裁判 Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lldSubmitted: 510  Accepted: 336[Submit][Status][Web Board] Description 大家知道我们学校的OnlineJudge吗?,你知道他会告诉你什么呢? Compiling : 您提交的代码正在被编译.Running : 您的程序正在OJ上运行.Judging : OJ