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 ...
随机推荐
- ylbtech-LanguageSamples-PartialTypes(部分类型)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-PartialTypes(部分类型) 1.A,示例(Sample) 返回顶部 “分部类型 ...
- 解决html视频播放只有声音没有图像的办法
HTML5中并没有指定视频解码器,它留给了浏览器来决定. MP4有四种编码格式(MPEG4(DivX),MPEG4(Xvid),AVC(H264),HEVC(H265)): 只有使用AVC(H264) ...
- python 实现计算数独
输入文件格式: 008309100900060004007504800036000540001000600042000970005907300600010008004608200 输出结果: yuan ...
- Linux 变量引用和命令替换
1.变量引用 name=Andy echo $name 或 echo ${name} 2.命令替换 把命令的执行结果赋值给变量,使用倒引号或者$() APP_HOME=`pwd` 或 APP_HOME ...
- 解决rails4.0中send_file文件下载两次的问题
之前在开发文件下载的功能时,我遇到了一个很奇怪的问题,点击下载链接,在chrome console中会出现两次请求,第一次返回200,下载的数据缓存在chrome的cache中,第二次返回304,直接 ...
- ListView改变字体
ListView中没有改变字体的属性和方法,所以需要用其他的方式.这里使用ArrayAdapter. 首先,创建一个TextView组件,用来作为Adapter的列表项组件. 在layout文 ...
- WIN7如何替换开机登录画面
1 把你的图片保存为backgroundDefault.jpg,并确保和你的屏幕分辨率相同 2 把下面的代码另存为@开启自定义登录界面.reg(注意格式为ASCII格式) Windows Regist ...
- vue - .postcssrc.js
描述:添加浏览器私缀(私缀是上世纪90年代浏览器大战的产物,也是现在新型浏览器支持某些新API,而其它浏览器不支持的证明!) 我们看看App.vue 再来看看打包后的css文件 一切都是靠你postc ...
- Android常用酷炫控件(开源项目)github地址汇总
转载一个很牛逼的控件收集帖... 第一部分 个性化控件(View) 主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Gallery.Gri ...
- Andorid上拉加载更多的几种实现方式
1.前言 Andriod中上拉加载更多的效果随处可见,因为一次性要展现的数据太多信息量太大的话,给用户的体验就很差(加载慢,界面卡顿.流量消耗大等),而加载更多可以控制每次加载条目的数量以达到快速加载 ...