A13399 | Phoenix and Balance
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Phoenix has $n$ coins with weights $2^1, 2^2, \dots, 2^n$ . He knows that $n$ is even.
He wants to split the coins into two piles such that each pile has exactly $\frac{n}{2}$ coins and the difference of weights between the two piles is minimized. Formally, let $a$ denote the sum of weights in the first pile, and $b$ denote the sum of weights in the second pile. Help Phoenix minimize $|a-b|$ , the absolute value of $a-b$ .
He wants to split the coins into two piles such that each pile has exactly $\frac{n}{2}$ coins and the difference of weights between the two piles is minimized. Formally, let $a$ denote the sum of weights in the first pile, and $b$ denote the sum of weights in the second pile. Help Phoenix minimize $|a-b|$ , the absolute value of $a-b$ .
输入格式
The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \le t \le 100$ ) — the number of test cases.
The first line of each test case contains an integer $n$ ( $2 \le n \le 30$ ; $n$ is even) — the number of coins that Phoenix has.
The first line of each test case contains an integer $n$ ( $2 \le n \le 30$ ; $n$ is even) — the number of coins that Phoenix has.
输出格式
For each test case, output one integer — the minimum possible difference of weights between the two piles.
输入输出样例
输入 #1
2 2 4
输出 #1
2 6
In the first test case, Phoenix has two coins with weights $2$ and $4$ . No matter how he divides the coins, the difference will be $4-2=2$ .
In the second test case, Phoenix has four coins of weight $2$ , $4$ , $8$ , and $16$ . It is optimal for Phoenix to place coins with weights $2$ and $16$ in one pile, and coins with weights $4$ and $8$ in another pile. The difference is $(2+16)-(4+8)=6$ .
In the second test case, Phoenix has four coins of weight $2$ , $4$ , $8$ , and $16$ . It is optimal for Phoenix to place coins with weights $2$ and $16$ in one pile, and coins with weights $4$ and $8$ in another pile. The difference is $(2+16)-(4+8)=6$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted