[NICA #2] 爱与不爱
[NICA #2] 爱与不爱
\mathcal{Update\ 2024.3.13}
简化一下思路。
前言
本题第一篇题解。
传送门
题目描述
给出一个
注:
简化思路
考虑将所有数优化到最小值:
随便选取两个数
让他们差尽可能最小化。
抽屉原理,当数列为
思路
我们可以思考若
那么我们就可以得到最小的
积不变,差小和小。
我们考虑分配这些
警钟敲烂
不开 long long 见祖宗。
AC Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
int x = 0,f = 1;char ch = getchar();
while (ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
return x * f;
}
inline int _2(int x){
int ans = 0;
while(x != 1){
x >>= 1;
ans++;
}
return ans;
}
int n, ans, a;
signed main(){
n = read();
for(int i = 1;i <= n;i++)
a = read(),ans += _2(a);
int sum = ans / n, cnt = ans - (sum * n);
cout << (1 << sum) * (n - cnt) + (1 << sum + 1) * cnt;
return 0;
}