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 ...
随机推荐
- 三种常见的部署Kubernetes的方式
三种常见的部署Kubernetes的方式 嘹亮的小号 Ghostcloud-001工号,资深Docker玩家,分布式系统研发11年. 关注他 容器技术将应用程序及其依赖关系与操作系统进行分离,不 ...
- [转]Using the Microsoft Connector for Oracle by Attunity with SQL Server 2008 Integration Services
本文转自:http://technet.microsoft.com/en-us/library/ee470675(v=sql.100).aspx SQL Server Technical Articl ...
- FPGA作为从机与STM32进行SPI协议通信---Verilog实现
一.SPI协议简要介绍 SPI,是英语Serial Peripheral Interface的缩写,顾名思义就是串行外围设备接口.SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用 ...
- 流畅的python第二章序列构成的数组学习记录
python内置序列类型概览 列表推导和生成器表达式 列表推导是构建列表的快捷方式,而生成器表达式可以用来创建其他任何类型的序列 列表推导的示例 >>>test = [i*2 for ...
- 【ACM】Largest prime factor
/*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors so four position ...
- list/tuple/dict/set
一.list(列表) 内置类型,长度可变的有序集合,索引从0开始,索引为负数是标识从右开始取,最右边第一个是-1,以此类推.里面的元素可以是不同类型的. 1.定义:a = [] #空列表 2.获取长度 ...
- Python中的__name__
python中if __name__ == '__main__': 的解析 经常会在代码的最下面看到if __name__ == '__main__':,现在就来介 绍一下它的作用. 模块是对象,并且 ...
- 算法笔记_163:算法提高 最大乘积(Java)
目录 1 问题描述 2 解决方案 1 问题描述 问题描述 对于n个数,从中取出m个数,如何取使得这m个数的乘积最大呢? 输入格式 第一行一个数表示数据组数 每组输入数据共2行: 第1行给出总共的数 ...
- php 获取ip地址方法
function getIP() { $ip=""; if(!empty($_SERVER['HTTP_CLIENT_IP'])){ $myip = $_SERVER['HTTP_ ...
- POI-word转html
package com.test.poiword; import android.app.Activity; import android.os.Bundle; import android.webk ...