hdu Distant Galaxy(遥远的银河)
Distant Galaxy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 111 Accepted Submission(s): 53
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?
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.
#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(遥远的银河)的更多相关文章
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- LA3695 Distant Galaxy
Distant Galaxy https://vjudge.net/problem/UVALive-3695 You are observing a distant galaxy using a te ...
- 2014 Asia AnShan Regional Contest --- HDU 5073 Galaxy
Galaxy Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5073 Mean: 在一条数轴上,有n颗卫星,现在你可以改变k颗 ...
- hdu 5073 Galaxy(2014acm鞍山亚洲分部 C)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5073 Galaxy Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 5073 Galaxy(2014acm鞍山亚洲分部 D)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5073 Galaxy Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5073 Galaxy(2014鞍山赛区现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5073 解题报告:在一条直线上有n颗星星,一开始这n颗星星绕着重心转,现在我们可以把其中的任意k颗星星移 ...
- ACM学习历程—HDU 5073 Galaxy(数学)
Description Good news for us: to release the financial pressure, the government started selling gala ...
- hdu 5073 Galaxy(2014 鞍山现场赛)
Galaxy Time Limit: 2000/1000 MS (J ...
- HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)
Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total S ...
随机推荐
- phpok -- 域名问题
nginx会改变连接的baseurl, 所以要改变nginx的server name的配置. 将网站改为静态也需配置nginx.
- 翻译:Spring-Framework-Reference Document:15.2-DispatcherServlet
写在前面的话: 最近被项目的代码折腾的死去活来的,其实框架也没有那么难理解,只是自己的Web基础太差,被Request和Response这一对神雕侠侣坑到泪流满面!今天捣腾了一下Spring We ...
- jquery一键控制checkbox全选,反选,全不选。
jquery attr()方法获取标签的 checked 会有问题,所以用了 prop() 方法. Hml的checkbox没有加name,只用了 div 嵌套. 如有更好的方法,望指点!! //全选 ...
- SQL Compare 10.4.8.87 Edition 数据库比较工具 完全破解+使用教程
一.使用教程 SQL Compare是编程人员常用的比较两个数据库之间差异的工具.可以用来比较数据库里面的对象.比如存储过程,数据库中的数据,表的结构. 下面我就简单介绍一下如何使用 1.选择要比较的 ...
- String格式化参数整理
Java String格式话参数整理如下: conversion:转换格式,可选的格式有: d 整数型(十进制) c Unicode字符 b Boolean值 s String f 浮点数(十进制) ...
- 扩展Jquery方法创建LigerUI Grid
///** //*封装jquery get请求ajax //*author:叶明龙 //*time:2012-12-10 //*/ function getAjax(url, para, fn) { ...
- HTML/CSS方法实现下拉菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C#秘密武器之多线程——基础
多线程概述 什么是进程? 当一个程序开始运行时,它就是一个进程,进程包括运行中的程序和程序所使用到的内存和系统资源.而一个进程又是由多个线程所组成的. 什么是线程? 线程是程序中的一个执行流,每个线程 ...
- Apatche httpd + Django + Mysql web server 搭建
Required: httpd: 2.4.18 django : 1.8.7 mysql: 5.7.10 MySQL-python: 1.2.3 mod_wsgi: 4.4.21 Offical Do ...
- 解决RegexKitLite编译报错
原地址:http://blog.csdn.net/kepoon/article/details/7586861 在编译RegexKitLite的时候,报错如下: Undefined symbols f ...