307799: CF1419A. Digit Game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Digit Game

题意翻译

存在位数为 $n$ 的数,从高位到低位依次为 $1,2,3,\cdots,n$。 A 和 B 轮流对数做标记,A 只可标记奇数位上的数,B 只可标记偶数位上的数字,一个数仅能标记一次。 若最后剩下的数是奇数,A 胜出,反之 B 胜出。若 A 胜出,输出 $1$,反之输出 $2$。 我们假定两位选手都能做出最佳的选择。

题目描述

Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play $ t $ matches of a digit game... In each of $ t $ matches of the digit game, a positive integer is generated. It consists of $ n $ digits. The digits of this integer are numerated from $ 1 $ to $ n $ from the highest-order digit to the lowest-order digit. After this integer is announced, the match starts. Agents play in turns. Raze starts. In one turn an agent can choose any unmarked digit and mark it. Raze can choose digits on odd positions, but can not choose digits on even positions. Breach can choose digits on even positions, but can not choose digits on odd positions. The match ends, when there is only one unmarked digit left. If the single last digit is odd, then Raze wins, else Breach wins. It can be proved, that before the end of the match (for every initial integer with $ n $ digits) each agent has an ability to make a turn, i.e. there is at least one unmarked digit, that stands on a position of required parity. For each of $ t $ matches find out, which agent wins, if both of them want to win and play optimally.

输入输出格式

输入格式


First line of input contains an integer $ t $ $ (1 \le t \le 100) $ — the number of matches. The first line of each match description contains an integer $ n $ $ (1 \le n \le 10^3) $ — the number of digits of the generated number. The second line of each match description contains an $ n $ -digit positive integer without leading zeros.

输出格式


For each match print $ 1 $ , if Raze wins, and $ 2 $ , if Breach wins.

输入输出样例

输入样例 #1

4
1
2
1
3
3
102
4
2069

输出样例 #1

2
1
1
2

说明

In the first match no one can make a turn, the only digit left is $ 2 $ , it's even, so Breach wins. In the second match the only digit left is $ 3 $ , it's odd, so Raze wins. In the third match Raze can mark the last digit, after that Breach can only mark $ 0 $ . $ 1 $ will be the last digit left, it's odd, so Raze wins. In the fourth match no matter how Raze plays, Breach can mark $ 9 $ , and in the end there will be digit $ 0 $ . It's even, so Breach wins.

Input

题意翻译

存在位数为 $n$ 的数,从高位到低位依次为 $1,2,3,\cdots,n$。 A 和 B 轮流对数做标记,A 只可标记奇数位上的数,B 只可标记偶数位上的数字,一个数仅能标记一次。 若最后剩下的数是奇数,A 胜出,反之 B 胜出。若 A 胜出,输出 $1$,反之输出 $2$。 我们假定两位选手都能做出最佳的选择。

加入题单

上一题 下一题 算法标签: