# UVA - 1382 Distant Galaxy

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 110;

struct point{
int x,y;
bool operator < (const point &s)const {
return x < s.x;
}
}P[MAXN];
int n,m,y[MAXN],on[MAXN],on2[MAXN],Left[MAXN];

int solve(){
sort(P,P+n);
sort(y,y+n);
m = unique(y,y+n) - y;
if (m <= 2)
return n;
int ans = 0;
for (int a = 0; a < m; a++)
for (int b = a+1; b < m; b++){
int ymin = y[a],ymax = y[b];

int k = 0;
for (int i = 0; i < n; i++){
if (i == 0 || P[i].x != P[i-1].x){
k++;
on[k] = on2[k] = 0;
Left[k] = Left[k-1] + on2[k-1] - on[k-1];
}
if (P[i].y > ymin && P[i].y < ymax)
on[k]++;
if (P[i].y >= ymin && P[i].y <= ymax)
on2[k]++;
}
if (k < 2)
return n;
int M = 0;
for (int j = 1; j <= k; j++){
ans = max(ans,Left[j]+on2[j]+M);
M = max(M,on[j]-Left[j]);
}
}
return ans;
}

int main(){
int cas = 0;
while (scanf("%d",&n) != EOF && n){
for (int i = 0; i < n; i++){
scanf("%d%d",&P[i].x,&P[i].y);
y[i] = P[i].y;
}
printf("Case %d: %d\n",++cas,solve());
}
return 0;
}

#### HDU 6052 2017 Multi-University Training Contest - Team 2 1008 To My Boyfriend：计数问题

2017-07-28 18:15:29

#### 最大子矩阵问题&悬线法 学习笔记

2016-01-17 10:49:54

#### [Vijos1055]奶牛浴场（极大子矩形）

2016-11-07 20:25:13

#### 蓝桥杯 基础练习 矩形面积交 【简单几何】

2017-12-21 15:08:51

#### vijos1056 图形面积 离散化

2016-11-04 21:33:36

#### UVA 1382 - Distant Galaxy

2014-05-04 13:07:06

#### UVa:1382 Distant Galaxy

2014-03-08 11:38:05

#### uva 1382 - Distant Galaxy

2013-03-28 14:46:40

#### UVA 1382 Distant Galaxy

2014-06-14 20:41:24

#### uva 1382 - Distant Galaxy

2013-04-13 00:33:06