牛客练习赛38 - A出题人的RP值 (思维水题)

在这里插入图片描述

水题, 排序从小到大遍历, 每次只和大于自身的RP平分(要不然还不如不分)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const LL maxn = 1e5+10;

LL n, x;
LL a[maxn];
bool cmp(LL a, LL b) {return a < b;}
int main()
{
    cin >> n >> x;
    for(int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a+n, cmp);
    double ans = x;
    for(int i = 0; i < n; i++){
        if(a[i] > ans)
            ans = (double)(ans+a[i])/2;
    }
    printf("%.3f\n",ans);

	return 0;
}

猜你喜欢

转载自blog.csdn.net/a1097304791/article/details/86551905