PAT(A)1125 Chain the Ropes (25point(s))

在这里插入图片描述

Sample Input

8
10 15 12 3 4 13 1 15

Sample Output

14

思路:
贪心,然后求不大于的值。
代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

#define endl '\n'

typedef long long ll;

double a[10004];

int main()
{
    int n;

    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    sort(a, a + n);

    double s = a[0];

    for (int i = 0; i < n; ++i)
    {
        s = (s + a[i]) * 1.0 / 2;
    }

    cout << floor(s) << endl;

    return 0;
}

发布了161 篇原创文章 · 获赞 7 · 访问量 7086

猜你喜欢

转载自blog.csdn.net/weixin_43778744/article/details/104142463