【题解】1125 Chain the Ropes (25分)⭐⭐ 【思维】

【题解】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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值