LA3695 - Distant Galaxy

原创 2015年07月10日 21:13:56
\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;
}


 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fljssj/article/details/46835113

LA3695

题目大意: 求出一个矩形可以包含的最多的星星的数量。思路: 用left数组存位于i左边的上下边界的数量,on数组存不包括上下边界的竖线上包含几个星星,用on2数组存包括上下边界的竖线上包含几个星星...
  • vv494049661
  • vv494049661
  • 2016-01-28 11:39:13
  • 248

LA 3695 Distant Galaxy 扫描线 -

题目地址:http://vjudge.net/problem/UVALive-3695 思路来自刘汝佳 矩形的每条边上肯定会有个点 题意的矩形是指水平,竖直边组成的矩形,并非斜的 那么可以根据...
  • qq_34446253
  • qq_34446253
  • 2016-10-16 18:11:50
  • 147

部分枚举(遥远的银河,LA 3695)

一开始没看清题,以为不一定平行。。。然后就不会了。。。 看了题解写了一遍,发现求某个值最好写在一个函数里,否则有时候代码中间要出一个特例就会很麻烦,甚至要goto。写在函数里一个return...
  • xl2015190026
  • xl2015190026
  • 2016-10-27 15:54:24
  • 244

LA 3695 Distant Galaxy

题目LA 3695 Distant Galaxy题解没啥好说的,先离散, 我是枚举两行,固定两行之后就成了序列上的问题了。sum[i]表示两行一共的横向前缀和,f[i]表示第i列在这两行中间的有多少,...
  • QWsin
  • QWsin
  • 2016-12-07 11:38:14
  • 224

《算法竞赛入门经典——训练指南》第一章相关内容

《算法竞赛入门经典——训练指南》第一章相关内容             目录(?)[+] 问题求解策略 General Problem Solving Techniques...
  • u011794223
  • u011794223
  • 2014-04-11 10:43:36
  • 518

Shanghai 2006,UVaLive(LA) 3695 Distant Galaxy题解

Vjudge传送门题意:是说给出一个平面上的n个点,现在要找一个矩形,使得边界上包含最多的矩形。题解:…平时做过找出一个固定大小的矩形然后找包含最多的星星的时候能包含多少颗星星,而没有做过这种题,当我...
  • NOIAu
  • NOIAu
  • 2017-09-06 18:26:21
  • 132

LA 3695(p52)----Distant Galaxy

#include #define debu using namespace std; const int maxn=100+50; struct point { int x,y; bo...
  • wang2147483647
  • wang2147483647
  • 2016-03-23 21:51:23
  • 158

LA 3695 Distant Galaxy (部分枚举+扫描法)

LA3695 Distant Galaxy题目大意:一个平面上给出n(1
  • The_useless
  • The_useless
  • 2016-12-09 20:37:00
  • 204

LAoj 3695 - Distant Galaxy (DP&几何)好题高效

You are observing a distant galaxy using a telescope above the Astronomy Tower, and you think thata ...
  • yanghui07216
  • yanghui07216
  • 2016-02-26 11:25:07
  • 267

1382 - Distant Galaxy(技巧枚举+离散化)

You are observing a distant galaxy using a telescope above the Astronomy Tower, and you think that a...
  • u011217342
  • u011217342
  • 2014-02-07 01:00:54
  • 1514
收藏助手
不良信息举报
您举报文章:LA3695 - Distant Galaxy
举报原因:
原因补充:

(最多只允许输入30个字)