ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #638 A.Phoenix and Balance(水题)

2020-05-02 14:51:16  阅读:333  来源: 互联网

标签:Phoenix 水题 638 coins sum1 fpow weights long


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 |a−b||a−b|, the absolute value of a−ba−b.

Input

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

The first line of each test case contains an integer nn (2≤n≤302≤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
因为两组的size都是n/2,所以最大的放进一组后,这组剩下的n/2-1个数一定都得是最小的(等比数列性质可知,an>sigma ai(i= 1 to n-1))。
#include <bits/stdc++.h>
using namespace std;
long long fpow(long long a,long long b)
{
    long long ans=1;
    for(;b;b>>=1)
    {
        if(b&1)ans*=a;
        a*=a;
    }
    return ans;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n,sum1=0,sum2=0;
        cin>>n;
        sum1+=fpow(2,n);
        sum1+=fpow(2,n/2)-2;
        sum2=fpow(2,n+1)-2-sum1;
        cout<<abs(sum1-sum2)<<endl;
    }
    return 0;
}

 



标签:Phoenix,水题,638,coins,sum1,fpow,weights,long
来源: https://www.cnblogs.com/lipoicyclic/p/12818074.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有