首页 > 其他分享 >abc236 E - Average and Median

abc236 E - Average and Median

时间:2023-01-19 16:12:38浏览次数:54  
标签:le ok int double Average Median mid 1e9 abc236

题意:

在给定数组中选数,要求任意相邻的两数至少选一个。问选出来的数的最大平均数和最大中位数

\(n\le 1e5, 1\le a_i\le 1e9\)

思路:

平均数、中位数的典中典二分+转化

this way: https://blog.csdn.net/Mr_dimple/article/details/122679274

const int N = 1e5 + 5;
int n, a[N];
void sol() {
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
{
    auto ok = [&](double x) {
        static double f[N]; f[1] = a[1] - x;
        for(int i = 2; i <= n; i++)
            f[i] = max(f[i - 1], f[i - 2]) + a[i] - x;
        return max(f[n], f[n - 1]) >= 0;
    };
    double l = 1, r = 1e9;
    int _ = 500; while(_--) { //实测40次也能AC
        double mid = (l + r) / 2;
        if(ok(mid)) l = mid; else r = mid;
    }
    cout << fixed << setprecision(9) << l << '\n';
}
{
    auto ok = [&](int x) {
        static int f[N]; f[1] = (a[1] >= x ? 1 : -1);
        for(int i = 2; i <= n; i++)
            f[i] = max(f[i - 1], f[i - 2]) + (a[i] >= x ? 1 : -1);
        return max(f[n], f[n - 1]) > 0;
    };
    int l = 1, r = 1e9;
    while(l < r) {
        int mid = l + (r - l + 1) / 2; //防爆int
        if(ok(mid)) l = mid; else r = mid - 1;
    }
    cout << l << '\n';
}
}

标签:le,ok,int,double,Average,Median,mid,1e9,abc236
From: https://www.cnblogs.com/wushansinger/p/17061684.html

相关文章

  • CF1761F Anti-median (Easy Version)
    称一个排列是好的,当且仅当对于所有\(m\)都满足所有长度为\(2m+1\)的子串的中位数不在第\(m+1\)个。给定一个一些数被替换成\(-1\)的排列\(p\),你需要统计所有可能......
  • 时间序列分析 Tsfresh 基于统计学的时间序列分析方法 3、差分整合移动平均自回归模型(A
    原文链接:点这里在了解了AR和MA模型后,我们将进一步学习结合了这两者的ARIMA模型,ARIMA在时间序列数据分析中有着非常重要的地位。但在这之前,让我们先来看ARIMA的简化版ARMA......
  • AGC006D Median Pyramid Hard
    ​​\(AGC006D\)\(Median\)\(Pyramid\)\(Hard\)​​一、题目描述二、题目解析这道例题看到时毫无头绪,因为课程是二分,所以往二分的方向想,猜到是二分枚举最上面的那个数是......
  • [TOP]load average 负载相关
    如何判断系统是否已经OverLoad?loadaverage的值小于CPU数量+1为正常 loadaverage的值/CPU数量=每个核消息等待处理数 一般是会根据15分钟那个load平均值为首先。loa......
  • LeetCode-Java-637. Average of Levels in Binary Tree
    题目Givenanon-emptybinarytree,returntheaveragevalueofthenodesoneachlevelintheformofanarray.Example1:Input:3/\920/\15......
  • Median
    Medianhttp://poj.org/problem?id=3579 思路参考:https://www.cnblogs.com/sky-stars/p/11317030.html lower_boundhttp://c.biancheng.net/view/7521.html ......
  • LeetCode:295. Find Median from Data Stream
    LeetCode:295.FindMedianfromDataStream题目描述Medianisthemiddlevalueinanorderedintegerlist.Ifthesizeofthelistiseven,thereisnomiddleval......
  • [LeetCode] 2256. Minimum Average Difference
    Youaregivena 0-indexed integerarray nums oflength n.The averagedifference oftheindex i isthe absolute difference betweentheaverageoft......
  • 【UVA 1451】Average
    题意:给出一个长度为n的01序列,要你求出一段至少长度为L的连续子序列,该子序列的数字的平均值最大,多解尽量保证长度小,在保证起点编号尽量小,求出起点和终点编号。......
  • 『题解』Codeforces 1758B XOR = Average
    Description构造一个\(a\)序列,使\(a_1\oplusa_2\oplusa_3\oplus\cdots\oplusa_n=\dfrac{sum(a)}{n}\)。Solution第一眼看到这道题,我想到的是分情况讨论。......