CF1348A.Phoenix and Balance

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Phoenix has nn coins with weights 21,22,…,2n2^1, 2^2, \dots, 2^n. He knows that nn is even.

He wants to split the coins into two piles such that each pile has exactly n2\frac{n}{2} coins and the difference of weights between the two piles is minimized. Formally, let aa denote the sum of weights in the first pile, and bb denote the sum of weights in the second pile. Help Phoenix minimize ∣a−b∣|a-b|, the absolute value of a−ba-b.

凤凰有 nn 枚硬币,其重量分别为 21,22,…,2n2^1, 2^2, \dots, 2^n。他已知 nn 是偶数。

他希望将这些硬币分成两堆,使得每堆恰好包含 n2\frac{n}{2} 枚硬币,并使两堆的总重量之差最小。形式化地说,设 aa 表示第一堆的总重量,bb 表示第二堆的总重量。请帮助凤凰最小化 ∣a−b∣|a-b|(即 a−ba-b 的绝对值)。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case contains an integer nn (2≤n≤302 \le n \le 30; nn is even) — the number of coins that Phoenix has.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤302 \le n \le 30;且 nn 为偶数),表示凤凰拥有的硬币数量。

输出格式

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 22 and 44. No matter how he divides the coins, the difference will be 4−2=24-2=2.

In the second test case, Phoenix has four coins of weight 22, 44, 88, and 1616. It is optimal for Phoenix to place coins with weights 22 and 1616 in one pile, and coins with weights 44 and 88 in another pile. The difference is (2+16)−(4+8)=6(2+16)-(4+8)=6.

在第一个测试用例中,凤凰有两枚重量分别为 22 和 44 的硬币。无论他如何划分这些硬币,差值均为 4−2=24-2=2。

在第二个测试用例中,凤凰有四枚重量分别为 22、44、88 和 1616 的硬币。最优策略是将重量为 22 和 1616 的硬币放在一堆,将重量为 44 和 88 的硬币放在另一堆。此时差值为 (2+16)−(4+8)=6(2+16)-(4+8)=6。

输入解题思路,AI测评打分。不知道怎么写?

首页