题目链接
1. 坐标值比较大,所以离散化坐标
2. 坐标的绝对值不超过10^9,说明可能有负数,所以把全部坐标移动转换为正数(加上10^9)
3. mat[i][j] ,表示(0,0) (i, j)为对顶点矩形之内包括边界上有多少个点。
4. 枚举矩形的上下界,然后选择左右边界。 对于确定的左边界left和右边界right, 假设是下图的R3是left, L3是right,那么数量为:
L1 + L2 + L3 - (R1+R2) + R3.
为了要使得以L3为右边界的矩形上的点最多,那么应该使得 R3-(R1+R2)的值最大。
所以,枚举右边界j, 维护保存j左边的R3-(R1+R2)的最大值,只要O(n)就可以确定答案了。
5. 需要注意的是所有点可能都在同一条直线上,所以给横坐标和右坐标都另外添加一个点
代码:
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN = 110;
const int ADD = 1e9+10;
int n;
int arr[MAXN][2];
int mat[MAXN][MAXN];
int X[MAXN], Y[MAXN], row, col;
inline int findID(int* A, int len, int x){
return lower_bound(A, A+len, x)-A+1;
}
inline void input(){
row = 1, col = 1;
X[0] = Y[0] = 0;
for(int i=0; i<n; ++i){
scanf("%d%d", &arr[i][0], &arr[i][1]);
X[row++] = arr[i][0] += ADD;
Y[col++] = arr[i][1] += ADD;
}
sort(X, X+row);
row = unique(X, X+row)-X;
sort(Y, Y+col);
col = unique(Y, Y+col)-Y;
memset(mat, 0, sizeof(mat));
for(int i=0; i<n; ++i){
int a = findID(X, row, arr[i][0]);
int b = findID(Y, col, arr[i][1]);
mat[a][b] = 1;
}
for(int i=1; i<=row; ++i){
for(int j=1; j<=col; ++j)
mat[i][j] += mat[i][j-1]+mat[i-1][j]-mat[i-1][j-1];
}
}
inline int solve(){
int ans = 1;
// 枚举上下界
for(int up=1; up<row; ++up){
for(int down=up+1; down<=row; ++down){
int maxx = mat[down][1]-mat[up-1][1];
for(int i=2; i<=col; ++i){
int right = mat[down][i]-mat[down-1][i]
+ mat[up][i]-mat[up-1][i]
+ mat[down-1][i]-mat[up][i]
- (mat[down-1][i-1]-mat[up][i-1]);
ans = max(ans, right+maxx);
int tmp = mat[down][i]-mat[up-1][i]
- (mat[down][i-1]-mat[up-1][i-1]);
tmp -= mat[down][i]-mat[down-1][i]
+ mat[up][i]-mat[up-1][i];
if(tmp > maxx) maxx=tmp;
}
}
}
return ans;
}
int main(){
int cas=1;
while(~scanf("%d", &n) && n){
input();
printf("Case %d: %d\n", cas++, solve());
}
return 0;
}
分享到:
相关推荐
Distant galaxy
Mon-depot-distant
SF Distant Galaxy
entrepot-distant:Unentrepot遥远
DISTANT
Distant supervision 相关文献 Distant supervision 相关文献
Two problems arise when using distant su- pervision for relation extraction. First, in this method, an already existing knowl- edge base is heuristically aligned to texts, and the alignment results ...
Hopefully I will be able to attend your seminar in the not-too-distant future. Randall R. Hawley, Automation Technician, Eli Lilly & Co. The best computer book writing I have seen. Tom Holland
遥远的贝斯版权所有(c)2019-2021 该存储库包含distant-bes的代码,一个用于将构建结果注入实现服务的库。安装为了安装该库,请克隆此存储库并运行pip install distant-bes/ 。兼容性该库已经针对构建事件协议的...
Java 项目说明, 简单的例子能够说明如果列举项目类别
遥远的世界-宇宙-翻译遥远的世界宇宙的翻译#Installation:将lange 文件夹(例如DE)的内容复制到Distant Worlds Universe 文件夹(不是语言文件夹本身!)。 你应该先备份! #Credits 初始翻译来自 ! 欢迎所有帮助...
利用腔的输入和输出过程产生基于氮空缺中心的GHZ态纠缠,郑安寿,吕新友,本文提出了一种替代方案实现N量子比特的氮空位中心分布在不同的光子晶体纳腔的GHZ态纠缠,该方案的实现是基于光子的输入和输出过程�
Distant Supervised Relation Extraction with Cost-Sensitive Loss
代码片段: <h1 class='dilate'>Dilate ...<h1 class='distant-top'>Distant Top <h1 class='distant-front'>Distant Front <h1 class='diff1'>Diffused Light <h1 class='bevel'>Bevel</h1>
Deep Ranking Based Cost-sensitive Multi-label Learning for Distant Supervision Relation Extraction
噪音鲁棒的神经网络关系抽取模型,姜廷松,穗志方,关系抽取的目标是从文本中自动抽取实体间关系,远程监督能够自动标注训练数据,使得关系抽取可以面向大规模语料展开。远程监督面临�
Blocky distant lights 2.sut
遥远的阅读味道Projekt“远距离阅读品味” zum Kurs“数字人文科学”
BTK包含C ++和Python库,这些库实现了语音处理和麦克风阵列技术,例如语音特征提取,语音增强,扬声器跟踪,波束成形,混响和回声消除算法。 Millennium ASR提供了用于自动语音识别的C ++和python库。...
WebRTC