CF A. Phoenix and Balance Codeforces Round #638 (Div. 2) 5月1号

Posted ahijing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF A. Phoenix and Balance Codeforces Round #638 (Div. 2) 5月1号相关的知识,希望对你有一定的参考价值。

A. Phoenix and Balance
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Phoenix has nn coins with weights 21,22,,2n21,22,…,2n. He knows that nn is even.

He wants to split the coins into two piles such that each pile has exactly n2n2 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 |ab||a−b|, the absolute value of aba−b.

Input

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

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

Output

For each test case, output one integer — the minimum possible difference of weights between the two piles.

Example
input
Copy
2
2
4
output
Copy
2
6
Note

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 42=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.

 

这题的意思就是,他有n个硬币(n是偶数)然后放在两个盘子里然后求相减最小;所以很自然的我们可以想到先放前n/2-1个在一个盘子再把最后一个放进去,因为成指数增加,所以这个盘子肯定重;

 1 #include <bits/stdc++.h>
 2 const int maxn=1e5+50;
 3 const int INF=0x3f3f3f3f;
 4 using namespace std;
 5 int main(){
 6     int t;
 7     cin>>t;
 8     while(t--){
 9         int n;
10         cin>>n;
11        double ans=pow(2.0, n*1.0/2);//求前n项和化简得到的公式为ans=2*(2^(n/2)-1)
12        ans=(ans-1)*2;
13        cout<<ans<<
;    
14     } 
15 
16 
17 return 0;
18 }

 

 

May I love u;

五月快乐

 

 

以上是关于CF A. Phoenix and Balance Codeforces Round #638 (Div. 2) 5月1号的主要内容,如果未能解决你的问题,请参考以下文章

A. Phoenix and Gold

CF1348D Phoenix and Science(思维)

CF1348E Phoenix and Berries(dp)

[CF1348D] Phoenix and Science - 贪心

[CF1348D] Phoenix and Science - 贪心

[CF1515F]Phoenix and Earthquake