CodeForces 1348-A Phoenix and Balance(思维)

CodeForces 1348-A Phoenix and Balance(思维)

https://codeforces.com/contest/1348/problem/A

 

 

题意:

把21,22,23,24,……2n(n为偶数)均分成两部分,求他们的最小差值

 

思路:

我们知道21+22+23+24+2n-1=2n-1,2n比前面所有数的和还大,所以我们让2n和前面的n/2 -1个数分成一组,剩下的分到另一组即可

 

#include <bits/stdc++.h>
typedef long long LL;
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1e9+7;
const int maxn = 1e5+10;
using namespace std;
 
int main()
{
    #ifdef DEBUG
    freopen("sample.txt","r",stdin); //freopen("data.out", "w", stdout);
    #endif
    
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        LL ans = (1<<n);
        for(int i=1;i<=n-1;i++)
        {
            if(i<n/2) ans+=(1<<i);
            else ans-=(1<<i);
        }
        printf("%lld\n",ans);
    }
    
    return 0;
}

 

-

posted @ 2020-05-02 15:07  jiamian22  阅读(339)  评论(0编辑  收藏  举报