# 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;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：UVA - 1382 Distant Galaxy 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)