xsy子矩形
- 考虑一种解题方法,枚举上下边界L,R, 然后二分答案T,我们要判断的是否存在
\]
- 也就是
\]
- 维护前缀最小值即可
- 然后这样是三次方的, 我们考虑random_shuffle一下枚举的序列, 然后查询的时候就先看一下当前的ans + eps是否可行, 不可行的话就不进行二分直接退出
- 这样期望是会进行lnn次的二分, 就赢了
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define M 515
#define ll long long
#define mmp make_pair
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
const double eps = 1e-10, inf = 5e13;
double ans = -1e9;
ll sum[M][M], n, tp, ver[M], xl, xr, yl, yr;
pair<int, int> note[M * M];
ll get(int xa, int ya, int xb, int yb) {
return sum[xb][yb] - sum[xa - 1][yb] - sum[xb][ya - 1] + sum[xa - 1][ya - 1];
}
bool check(double T, int len, int l, int r) {
double minn = 0, pl = 0;
double up = T * 2 * len;
for(int i = 1; i <= n; i++) {
double ver2 = ver[i] - T * 2 * i;
if(ver2 - minn >= up) {
if(T > ans) {
ans = T;
xl = l, yl = pl + 1, xr = r, yr = i;
}
return true;
}
if(ver2 < minn) minn = ver2, pl = i;
}
return false;
}
int main() {
//freopen("rectangle3.in", "r", stdin);
n = read();
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + read();
for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++) note[++tp] = mmp(i, j);
for(int i = 1; i <= tp; i++) {
int x = 1ll * rand() * rand() % i + 1;
swap(note[x], note[i]);
}
for(int i = 1; i <= tp; i++) {
int l = note[i].first, r = note[i].second;
for(int j = 1; j <= n; j++) ver[j] = get(l, 1, r, j);
if(!check(ans + eps, r - l + 1, l, r)) continue;
double L = ans, R = inf;
for(int j = 1; j <= 100; j++) {
double mid = (L + R) / 2.0;
if(!check(mid, r - l + 1, l, r)) R = mid;
else L = mid;
}
}
// cerr<< note[tp].first << " " << note[tp].second << "\n";
printf("%.10lf\n", ans);
cout << xl << " " << yl << "\n" << xr << " " << yr << "\n";
return 0;
}
xsy子矩形的更多相关文章
- LeetCode子矩形查询
LeetCode 子矩形查询 题目描述 请你实现一个类SubrectangleQueries,它的构造函数的参数是一个rows * cols的矩形(这里用整数矩阵表示),并支持以下两种操作: upda ...
- PKU 1050-To The Max(找矩形内元素最大和)
Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous s ...
- Vijos1055 奶牛浴场(极大化思想求最大子矩形)
思路详见 王知昆<浅谈用极大化思想解决最大子矩形问题> 写得很详细(感谢~....) 因为不太会用递推,所以用了第一种方法,时间复杂度是O(n^2),n为枚举的点数,对付这题绰绰有余 思路 ...
- [LeetCode] Number Of Corner Rectangles 边角矩形的数量
Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner rectang ...
- XJOI 3606 最大子矩形面积/LightOJ 1083 Histogram(单调栈/笛卡尔树)
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rec ...
- bzoj 1127 KUP —— 最大子矩形+答案构造
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1127 首先,把权值 > 2*k 的点作为“坏点”,然后在图中用悬线法找权值最大的子矩形 ...
- hiho 1476 - 矩形计数 容斥
题目链接 如图所示,在由N行M列个单位正方形组成的矩形中,有K个单位正方形是黑色的,其余单位正方形是白色的. 你能统计出一共有多少个不同的子矩形是完全由白色单位正方形组成的吗? ----------- ...
- P1578 奶牛浴场 有障碍点的最大子矩形
这题咕咕了很久终于写了\(QwQ\) 思路:扫? 提交:2次 错因:数据差评,第一次把矩形的长宽搞反了竟然只有一个点没有\(A\). 题解: 显然能成为答案的矩形的边界一定有障碍点或者与大矩形边界重合 ...
- [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
随机推荐
- unity中实现场景之间加载进度条
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; using UnityEngine.UI ...
- Beta 冲刺 (3/7)
Beta 冲刺 (3/7) 队名:第三视角 组长博客链接 本次作业链接 团队部分 团队燃尽图 工作情况汇报 张扬(组长) 过去两天完成了哪些任务 文字/口头描述 参与开发关键词提醒部分 展示GitHu ...
- [Leetcode 771]宝石和石子 Jewels and Stones HashSet简单应用
[题目] You're given strings J representing the types of stones that are jewels, and S representing the ...
- mysql group_concat(column) 函数替换成 oracle wm_concat(colum)
11gr2和12C上已经摒弃了wm_concat函数,所以只能手动创建该函数 解决办法: 一.解锁sys用户 alter user sys account unlock; 二.创建包.包体和函数 以s ...
- ionic3 使用swiper插件 实现轮播效果
由于app的更新迭代 我需要完成新版本设计图的开发 刚开始就遇到一个问题 首页的banner图需要实现某种效果 而ionic3自带的轮播图效果怎么改都改不到我想要的效果 效果图如下 自动播放 不断 ...
- Cordova编译报AAPT错误的解决方法
因为项目中同时使用cordova-hot-code-push-plugin和phonegap-plugin-barcodescanner,编译时报错:AAPT: error: resource and ...
- SpringBoot(三)thymeleaf+JPA+MySql
接着上一节的 第一步:在pom文件中加入以下代码: <!--JPA--> <dependency> <groupId>org.springframework.boo ...
- Git删除分支/恢复分支
• 删除一个已被终止的分支 如果需要删除的分支不是当前正在打开的分支,使用branch -d直接删除 git branch -d <branch_name> • 删除一个正打开的分支 如 ...
- sql语言 含有包含关系的查询 (含mysql 和sql sever)
一.sql中查询包含关系的查询 sql语句中包含关系可以使用 in 和exist,但有些时候仅仅用这两个是不够的,还有表示方法是 not exist(b expect a )可以表示a包含b. 二. ...
- idea的maven项目下spring与mybatis整合
两周前学习mybatis框架,参考了网上多位大神的博客,但因为各种原因(不解释)总是没法成功搭建环境并运行项目.周末花了点时间阅读了文档并整理之前琐碎的内容,解决掉之前遇到的问题.现将整合环境的关键步 ...