A14911 | Playoff
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Consider a playoff tournament where $2^n$ athletes compete. The athletes are numbered from $1$ to $2^n$ .
The tournament is held in $n$ stages. In each stage, the athletes are split into pairs in such a way that each athlete belongs exactly to one pair. In each pair, the athletes compete against each other, and exactly one of them wins. The winner of each pair advances to the next stage, the athlete who was defeated gets eliminated from the tournament.
The pairs are formed as follows:
- in the first stage, athlete $1$ competes against athlete $2$ ; $3$ competes against $4$ ; $5$ competes against $6$ , and so on;
- in the second stage, the winner of the match " $1$ – $2$ " competes against the winner of the match " $3$ – $4$ "; the winner of the match " $5$ – $6$ " competes against the winner of the match " $7$ – $8$ ", and so on;
- the next stages are held according to the same rules.
When athletes $x$ and $y$ compete, the winner is decided as follows:
- if $x+y$ is odd, the athlete with the lower index wins (i. e. if $x < y$ , then $x$ wins, otherwise $y$ wins);
- if $x+y$ is even, the athlete with the higher index wins.
The following picture describes the way the tournament with $n = 3$ goes.
Your task is the following one: given the integer $n$ , determine the index of the athlete who wins the tournament.
The tournament is held in $n$ stages. In each stage, the athletes are split into pairs in such a way that each athlete belongs exactly to one pair. In each pair, the athletes compete against each other, and exactly one of them wins. The winner of each pair advances to the next stage, the athlete who was defeated gets eliminated from the tournament.
The pairs are formed as follows:
- in the first stage, athlete $1$ competes against athlete $2$ ; $3$ competes against $4$ ; $5$ competes against $6$ , and so on;
- in the second stage, the winner of the match " $1$ – $2$ " competes against the winner of the match " $3$ – $4$ "; the winner of the match " $5$ – $6$ " competes against the winner of the match " $7$ – $8$ ", and so on;
- the next stages are held according to the same rules.
When athletes $x$ and $y$ compete, the winner is decided as follows:
- if $x+y$ is odd, the athlete with the lower index wins (i. e. if $x < y$ , then $x$ wins, otherwise $y$ wins);
- if $x+y$ is even, the athlete with the higher index wins.
The following picture describes the way the tournament with $n = 3$ goes.
Your task is the following one: given the integer $n$ , determine the index of the athlete who wins the tournament.
输入格式
The first line contains one integer $t$ ( $1 \le t \le 30$ ) — the number of test cases.
Each test case consists of one line containing one integer $n$ ( $1 \le n \le 30$ ).
Each test case consists of one line containing one integer $n$ ( $1 \le n \le 30$ ).
输出格式
For each test case, print one integer — the index of the winner of the tournament.
输入输出样例
输入 #1
2 3 1
输出 #1
7 1
The case $n = 3$ is shown in the picture from the statement.
If $n = 1$ , then there's only one match between athletes $1$ and $2$ . Since $1 + 2 = 3$ is an odd number, the athlete with the lower index wins. So, the athlete $1$ is the winner.
If $n = 1$ , then there's only one match between athletes $1$ and $2$ . Since $1 + 2 = 3$ is an odd number, the athlete with the lower index wins. So, the athlete $1$ is the winner.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted