LA3695 - Distant Galaxy

\epsfbox{p3694.eps}

Input 

There are multiple test cases in the input file. Each test case starts with one integer N , (1$ \le$N$ \le$100) , 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;
}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值