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个数分成一组,剩下的分到另一组即可
1 #include <bits/stdc++.h> 2 typedef long long LL; 3 #define pb push_back 4 const int INF = 0x3f3f3f3f; 5 const double eps = 1e-8; 6 const int mod = 1e9+7; 7 const int maxn = 1e5+10; 8 using namespace std; 9 10 int main() 11 { 12 #ifdef DEBUG 13 freopen("sample.txt","r",stdin); //freopen("data.out", "w", stdout); 14 #endif 15 16 int T; 17 scanf("%d",&T); 18 while(T--) 19 { 20 int n; 21 scanf("%d",&n); 22 LL ans = (1<<n); 23 for(int i=1;i<=n-1;i++) 24 { 25 if(i<n/2) ans+=(1<<i); 26 else ans-=(1<<i); 27 } 28 printf("%lld ",ans); 29 } 30 31 return 0; 32 }
-