当前位置:网站首页>【集训DAY3】挖金矿【二分答案】
【集训DAY3】挖金矿【二分答案】
2022-08-09 22:35:00 【VL——MOESR】
思路:
直接二分平均值,然后把数组全部减去平均值,贪心求每一列的最大值,然后判断是否合法就行了
c o d e code code
#include<iostream>
#include<cstdio>
using namespace std;
int n, m, tot;
double a[100010];
bool check(double x) {
double s1 = 0, s2 = 0, s3 = 0;
tot = 0;
for(int i = 1; i <= n; i ++) {
s1 = s2 = a[++ tot] - x;
for(int j = 2; j <= m; j ++)
s1 = s1 + a[++ tot] - x, s2 = max(s1, s2);
s3 += s2;
}
return s3 >= 0;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
tot ++, scanf("%lf", &a[tot]);
double l = 0, r = 1000000000.0, ans = 0;
while(l + 0.000001 < r) {
double mid = (l + r) / 2;
if(check(mid)) l = mid, ans = max(ans, mid);
else r = mid;
}
printf("%.4lf", ans);
return 0;
}
边栏推荐
猜你喜欢
2022-08-09 mysql/stonedb-子查询性能提升-概论
SRv6性能测量
如何正则匹配乱码?
《GB5084-2021》PDF下载
Technology feast!Huayun Data brings six topics to OpenInfra Days China
如何知道电脑开机记录?
技术盛宴!华云数据携六大议题亮相OpenInfra Days China
杭电多校-Counting Stickmen-(思维+组合数+容斥)
iNFTnews | 迪士尼如何布局Web3
[Interface Test] Decoding the request body string of the requests library
随机推荐
CMake使用记录
友元类和友元函数
JS--popstate事件--使用/教程/实例
ABAP中Collect的用法
联盟链技术应用的难点
金仓数据库 KingbaseGIS 使用手册(6.2. 管理函数)
SRv6性能测量
金仓数据库 KingbaseGIS 使用手册(6.3. 几何对象创建函数)
用哈希简单封装unordered_map和unordered_set
6款跨境电商常用工具汇总
JS基础笔记-关于对象
如何正则匹配乱码?
tiup cluster scale-out
k8s部署mysql
【面试高频题】可逐步优化的链表高频题
LiveData : Transformations.map和 Transformations.switchMap用法
tiup cluster template
位图的基本原理以及应用
A summary of 6 common tools for cross-border e-commerce
多线程是同时执行多个线程的吗