当前位置:网站首页>E - average and median
E - average and median
2022-06-25 02:20:00 【Harris-H】
E - Average and Median( Two points )
The first question has two answers x x x, Then you can count all the numbers − x -x −x, That is to meet the requirements ∑ ( a i − x ) ≥ 0 \sum (a_i-x)\ge 0 ∑(ai−x)≥0
Sure dp.
The second question is the same , Two points answer x x x, then b i = [ a i ≥ x ] b_i = [a_i\ge x] bi=[ai≥x]
So that is ∑ b i ≥ 0 \sum b_i\ge 0 ∑bi≥0
It's also dp.
Time complexity : O ( n l o g V ) O(nlogV) O(nlogV)
The difficulty is that I didn't think of it at the beginning How to calculate quickly after two points . I can dp.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inf 0x3f3f3f3f
#define mod 1000000007
#define m_p(a,b) make_pair(a, b)
#define mem(a,b) memset((a),(b),sizeof(a))
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef pair <int,int> pii;
#define MAX 300000 + 50
int n, m, k;
int tr[MAX];
double dp[MAX][2];
bool check1(double mid){
dp[0][0] = dp[0][1] = 0.0;
for(int i = 1; i <= n; ++i){
dp[i][0] = dp[i - 1][1];
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + tr[i] - mid;
}
if(max(dp[n][1], dp[n][0]) >= 0)return true;
else return false;
}
bool check2(int mid){
dp[0][0] = dp[0][1] = 0;
for(int i = 1; i <= n; ++i){
dp[i][0] = dp[i - 1][1];
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + (tr[i] >= mid ? 1 : -1);
}
if(max(dp[n][1], dp[n][0]) > 0)return true;
else return false;
}
void work(){
cin >> n;
for(int i = 1; i <= n; ++i)cin >> tr[i];
double l = 0, r = 1000000000.0;
while (r - l >= 1e-6) {
double mid = (l + r) / 2;
if(check1(mid))l = mid;
else r = mid;
}
int ll = 0, rr = 1000000000;
while (ll <= rr) {
int mid = (ll + rr) / 2;
if(check2(mid))ll = mid + 1;
else rr = mid - 1;
}
cout << r << '\n' << rr << endl;
}
int main(){
io;
work();
return 0;
}
边栏推荐
- Application of TSDB in civil aircraft industry
- 如何卸载cuda
- TSDB在民机行业中的应用
- 探索C语言程序奥秘——C语言程序编译与预处理
- 把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(4)—— 修改 oracle11g rac 集群的 scanIP
- Sumati gamefi ecological overview, element design in the magical world
- Intranet learning notes (7)
- Specific list of regular and safe domestic stock trading account opening
- Left hand dreams right hand responsibilities GAC Honda not only pays attention to sales but also children's safety
- yarn : 无法加载文件 C:\Users\xxx\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本
猜你喜欢

进入阿里做测试员遥不可及?这里或许有你想要的答案

Once beego failed to find bee after passing the go get command Exe's pit

Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification

元宇宙的生态圈

DDD concept is complex and difficult to understand. How to design code implementation model in practice?

文件系统 -- 磁盘基础知识和FAT32文件系统详细介绍

Left hand dreams right hand responsibilities GAC Honda not only pays attention to sales but also children's safety

都2022年了,你还不了解什么是性能测试?

File system - basic knowledge of disk and detailed introduction to FAT32 file system

Is it out of reach to enter Ali as a tester? Here may be the answer you want
随机推荐
Cusdis - lightweight, privacy first open source comment system | chain of the city
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
Please run IDA with elevated permissons for local debugging.
When an interface has an exception, how do you analyze the exception?
DDD概念复杂难懂,实际落地如何设计代码实现模型?
Kaggle 专利匹配比赛金牌方案赛后总结
当一个接口出现异常时候,你是如何分析异常的?
Build and train your own dataset for pig face recognition
linux上查看mysql的密码_Linux下MySQL忘记密码「建议收藏」
Beescms website penetration test and repair comments "suggestions collection"
random list随机生成不重复数
入坑机器学习:一,绪论
Left hand dreams right hand responsibilities GAC Honda not only pays attention to sales but also children's safety
Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
The ecosystem of the yuan universe
Of the seven levels of software testers, it is said that only 1% can achieve level 7
华为、阿里等大厂程序员真的好找对象吗?
中信证券手机开户是靠谱的吗?安全吗
[day 26] given the ascending array nums of n elements, find a function to find the subscript of target in nums | learn binary search
Intranet learning notes (6)