PAT (Advanced Level) Practice 1125 Chain the Ropes (25 分)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Nightmare_ak/article/details/84872733

贪心,越大的被除2的次数越少越好

#include<cstdio>
#include<algorithm>
using namespace std;

const int N=1e4+5;

int a[N];

int main()
{
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+n);
    for(int i=1;i<n;i++)
        a[i]=(a[i]+a[i-1])/2;
    printf("%d\n",a[n-1]);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Nightmare_ak/article/details/84872733