A13853 | Digit Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted