cf638 A. Phoenix and Balance(思维)
作者:互联网
https://codeforces.com/contest/1348/problem/A
题意:
把数组 \(2^1,2^2,2^3,\cdots,2^n\) 分成个数相等的两堆,最小化两堆的和之差的绝对值
\(n\) 为偶数
思路:
\(2^n\) 比其他所有数加起来还大,所以 \(2^1,2^2,\cdots,2^{n/2-1},2^n\) 放一堆,其他放另一堆
#include <bits/stdc++.h>
using namespace std;
signed main()
{
int t, n; cin >> t; while(t--)
{
cin >> n; int ans1 = 1<<n, ans2 = 0;
for(int i = 1; i < n/2; i++) ans1 |= (1<<i);
for(int i = n/2; i < n; i++) ans2 |= (1<<i);
cout << ans1-ans2 << '\n';
}
return 0;
}
标签:cf638,一堆,题意,Phoenix,int,cin,两堆,cdots,Balance 来源: https://www.cnblogs.com/wushansinger/p/15417650.html