【题解】1125 Chain the Ropes (25分)⭐⭐ 【思维】
题意:
n条绳子,已知每条长度,每对绳子打个结可生成新的绳子,长度位二者之和减半(向下取整),求最终可以构造出的最长的绳子长度
题解:
仔细思考一下,由于所有的绳子都要大家,只有尽可能的将两个小绳子在一块打结才能尽可能避免“浪费”。
所以排序就好了
经验小结:
#include<bits/stdc++.h>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef long long LL;
const int INF = 1 << 30;
const int MAXN = 1e4+10;
int n, a[MAXN];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> a[i];
sort(a+1, a+1+n);
int ans = a[1];
for(int i = 2; i <= n; ++i){
ans = (ans+a[i])/2;
}
cout << ans << endl;
return 0;
}