# LA3695 - Distant Galaxy

## Input

There are multiple test cases in the input file. Each test case starts with one integer N , (1N100) , the number of star systems on the telescope. N lines follow, each line consists of two integers: the X and Y coordinates of the K -th planet system. The absolute value of any coordinate is no more than 109 , and you can assume that the planets are arbitrarily distributed in the universe.

N = 0 indicates the end of input file and should not be processed by your program.

## Output

For each test case, output the maximum value you have found on a single line in the format as indicated in the sample output.

## Sample Input

10
2 3
9 2
7 4
3 4
5 7
1 5
10 4
10 6
11 4
4 6
0


## Sample Output

Case 1: 7

#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;
const int MAXN = 110;
int n;
int Left[MAXN], on[MAXN], on2[MAXN];
struct node
{
int x, y;
bool operator < (const node & a)const
{
return x < a.x;
}
}P[MAXN];
int y[MAXN];
int solve()
{
sort(P,P+n);
sort(y,y+n);
int m = unique(y,y+n) - y;//cout<<m<<endl;
if(m<=2)return n;
int ans = 0;
for(int i=1; i<m; i++)//上边界
{
for(int j=0; j<i; j++)//下边界
{
int l = 0;
Left[l] = 0;
on[l] = on2[l] = 0;
for(int k =0; k<n; )//从左到右选择竖线
{
//if(k==0||P[k].x!=P[k-1].x)
{
l++;
int s = 0;
Left[l] = Left[l-1];
on[l] =  on2[l] = 0;
if(P[k].y == y[i] || P[k].y == y[j])//在线上的点
{
Left[l] ++;
on[l] ++;
}
if(P[k].y<y[i]&&P[k].y>y[j]) s++;
k++;
while(k<n&&P[k].x==P[k-1].x)
{
if(P[k].y == y[i] || P[k].y == y[j])//在线上的点
{
Left[l] ++;
on[l] ++;
}
if(P[k].y<y[i]&&P[k].y>y[j]) s++;
k++;
}
on[l]+=s;
on2[l]+=s;
}
}

/*  cout<<"***"<<y[i]<<"---->"<<y[j]<<"***"<<endl;
for(int k=0; k<l; k++)
{
cout<<"Left["<<k<<"] = "<<Left[k]<<" , ";
cout<<"on["<<k<<"] = "<<on[k]<<" , ";
cout<<"on2["<<k<<"] = "<<on2[k]<<endl;
}
cout<<"*****************************"<<endl;*/
if(l<=2)return n;
int maxs=0;
for(int k=1; k<=l; k++)
{
ans = max(ans, Left[k] + on2[k] + maxs);
maxs = max(maxs,on[k]-Left[k]);
}
//ans = max(ans,maxs);

}
}
return ans;
}
int main()
{
int cs = 1;
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", cs++, solve());
}
return 0;
}


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

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