Distant Galaxy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 111    Accepted Submission(s): 53

Problem Description
You
are observing a distant galaxy using a telescope above the Astronomy
Tower, and you think that a rectangle drawn in that galaxy whose edges
are parallel to coordinate axes and contain maximum star systems on its
edges has a great deal to do with the mysteries of universe. However you
do not have the laptop with you, thus you have written the coordinates
of all star systems down on a piece of paper and decide to work out the
result later. Can you finish this task?

 
Input
There
are multiple test cases in the input file. Each test case starts with
one integer N , (1<=N<=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<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
struct T
{
int x;
int y;
bool operator <(const T& rhs) const{
return x<rhs.x;
}
}poin[];
// 具体可见大白书,51页
//y[]表示存储所有的y的值,on[]表示左边界,on2表示右边界
int y[],lef[],on[],on2[];
int t, m;
int solve()
{
sort(poin,poin+t);
sort(y,y+t);
m = unique(y,y+t) - y;//去除相同的元素,m表示去除相同的元素后,还有几个
if(m<=) return t; //如果只有两种y值表示所有点都在这两条线上,直接返回
int ans = ;
for(int a = ; a<m; a++)//枚举所有可能的上边界和下边界
for(int b = a+; b<m; b++)
{
int ymin =y[a];int ymax = y[b];
int k = ;
for(int i = ; i<t;i++)
{
if(i== || poin[i].x!=poin[i-].x) //判断前后的x值是否有相同的点
{
k++;
on[k] = on2[k] = ;
lef[k] = k== ? : lef[k-]+ on2[k-] - on[k-];//此时的lef不包括右边界在它上面的点
}
if(poin[i].y>ymin && poin[i].y<ymax) on[k]++;
if(poin[i].y>=ymin && poin[i].y<=ymax) on2[k]++;//on2 - on 表示在线上的点
}
if(k<=) return t;//这个地方表示少于两种的x值,只好返回本身了
int m = ;
for(int j = ;j<=k; j++)
{
ans = max(ans,lef[j]+on2[j]+m);// 大白书51页有详细介绍
m = max(m,on[j] - lef[j]); //
}
}
return ans;
}
int main()
{
int num = ;
while(scanf("%d",&t) && t)
{
for(int i = ;i<t; i++)
{
scanf("%d %d",&poin[i].x,&poin[i].y);
y[i] = poin[i].y;
}
printf("Case %d: %d\n",num,solve());
num++;
}
return ;
}

hdu Distant Galaxy(遥远的银河)的更多相关文章

  1. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  2. LA3695 Distant Galaxy

    Distant Galaxy https://vjudge.net/problem/UVALive-3695 You are observing a distant galaxy using a te ...

  3. 2014 Asia AnShan Regional Contest --- HDU 5073 Galaxy

    Galaxy Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5073 Mean: 在一条数轴上,有n颗卫星,现在你可以改变k颗 ...

  4. hdu 5073 Galaxy(2014acm鞍山亚洲分部 C)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5073 Galaxy Time Limit: 2000/1000 MS (Java/Others)   ...

  5. hdu 5073 Galaxy(2014acm鞍山亚洲分部 D)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5073 Galaxy Time Limit: 2000/1000 MS (Java/Others)   ...

  6. HDU 5073 Galaxy(2014鞍山赛区现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5073 解题报告:在一条直线上有n颗星星,一开始这n颗星星绕着重心转,现在我们可以把其中的任意k颗星星移 ...

  7. ACM学习历程—HDU 5073 Galaxy(数学)

    Description Good news for us: to release the financial pressure, the government started selling gala ...

  8. hdu 5073 Galaxy(2014 鞍山现场赛)

    Galaxy                                                                   Time Limit: 2000/1000 MS (J ...

  9. HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total S ...

随机推荐

  1. 版本控制SVN的使用笔记

    安装 客户端和服务端下载地址,打开网址,根据自己的操作系统下载对应的版本,window用户服务端一般安装的是VisualSVN,客户端安装TortoiseSVN,在实际工作中,我们一般只需要安装Tor ...

  2. 通过命名管道协议方式访问群集SQL的一个小问题

    原来的单机实例SQL如果开放命名管道协议访问可以在.Net程序的连接字符串中增加“;Net=dbnmpntw"以通过命名管道协议方式访问,但是当迁移到群集SQL后,.net通过它可能无法正常 ...

  3. DX12

    CD3DX12_DESCRIPTOR_RANGE1 的baseShaderRegister 用来指定 t0 t1 b0 b1...的index t0 srv b0 constant buffer u0 ...

  4. 关于Java的File类、字节流和字符流

    一.File类: 在Windows下的路径分隔符(\)和在Linux下的路径分隔符(/)是不一样的,当直接使用绝对路径时,跨平台会报No Such file or diretory异常. File中还 ...

  5. EPF与Myeclipse 增强代码自动智能提示

    摘自: http://blog.csdn.net/ylchou/article/details/7639467 数字证书文件,导入用. EPF文件是著名的软件开发工具——Eclipse(IDE)的配置 ...

  6. phantomjs 无法打开https网站解决方案

    最近测试原来的爬虫程序,发现phantomjs 无法打开https网站了,经过网上查下,发现需要在phantomjs定义的加以下参数 self.driver = webdriver.PhantomJS ...

  7. [视频解说]Java(JDK的下载安装及第一个程序执行)

    (JDK的下载安装及第一个程序执行) 内容:Java JDK 的安装以及HelloWorld 程序的执行 欢迎童鞋们前往围观 http://v.youku.com/v_show/id_XODA3Mzk ...

  8. g++动态库静态库混合链接

    今天编译一个程序时报错: g++ -static -o echo.fcgi echo_adaptor.o echo.o -L/usr/local/lib/ -lfastcgipp -L/usr/lib ...

  9. (转)Scala的“=>”符号简介

    Scala中的=>符号可以看做是创建函数实例的语法糖.例如:A => T,A,B => T表示一个函数的输入参数类型是“A”,“A,B”,返回值类型是T.请看下面这个实例: scal ...

  10. 利用jspx解决jsp后缀被限制拿shell

    有些struts2的站在web.xml里面设置url是jsp的格式就自动跳转主页的action,转换jsp后缀大小写还不解析.查了查有Tomcat默认jspx可以解析.看了看jspx的手册,那就好说了 ...