码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-05-02 09:52:32      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:col   specific   time   imu   org   another   sub   sam   意思   

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<<\n;    
14     } 
15 
16 
17 return 0;
18 }

 

 

May I love u;

五月快乐

 

 

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

标签:col   specific   time   imu   org   another   sub   sam   意思   

原文地址:https://www.cnblogs.com/ahijing/p/12816793.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!