当前位置:网站首页>【集训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;
}
边栏推荐
- complete knapsack theory
- 全面解析FPGA基础知识
- 【Burning】It's time to show your true strength!Understand the technical highlights of the 2022 Huawei Developer Competition in one article
- matplotlib散点图颜色分组图例
- YGG 经理人杯总决赛已圆满结束,来看看这份文字版总结!
- Qt 之 QDateEdit 和 QTimeEdit
- 用函数统计最长单词的字母数量
- 中国SaaS企业排名,龙头企业Top10梳理
- [Interface Test] Decoding the request body string of the requests library
- 领跑政务云,连续五年中国第一
猜你喜欢
Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
如何正则匹配乱码?
Gumbel distribution of discrete choice model
YGG 经理人杯总决赛已圆满结束,来看看这份文字版总结!
恭喜获奖得主 | 互动有礼获赠 Navicat Premium
深入理解多线程(第一篇)
《GB5084-2021》PDF下载
Qt 之 QDateEdit 和 QTimeEdit
A summary of 6 common tools for cross-border e-commerce
&& 不是此版本的有效语句分隔符
随机推荐
金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)
【接口测试】requests 库请求体字符串解码
直播平台怎么搭建,原生js实现编辑器撤消/恢复功能
2022-08-09 mysql/stonedb-subquery performance improvement-introduction
LeetCode952三部曲之三:再次优化(122ms -> 96ms,超51% -> 超91%)
34. Fabric2.2 证书目录里各文件作用
JS--hashchange事件--使用/教程
力扣:322. 零钱兑换
61.【快速排序法详解】
【哲理】读书的意义
Snap: 322. Change of Change
leetcode 20. Valid Parentheses 有效的括号(中等)
LiveData : Transformations.map and Transformations.switchMap usage
领跑政务云,连续五年中国第一
【哲理】事教人
国内BI厂商一览
linux上使用docker安装redis
2022年最新《谷粒学院开发教程》:10 - 前台支付模块
33. Fabric通道、组织、节点、权限间关系
Mysql集群 ShardingSphere