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 ;
}

最新文章

  1. android studio 2.0 GPU Debugger使用说明
  2. win7画板橡皮擦改变大小
  3. javascript解析引擎(每天有学习一点篇)
  4. 六间房 繁星 酷我 来疯 秀吧 新浪秀 直播播放器 Live 1.2
  5. fleetctl --help
  6. python中的md5加密
  7. [IT] 关闭笔记本的蜂鸣提示
  8. FFMPEG视音频编解码零基础学习方法-b
  9. java总结
  10. 关于Context []startup failed due to previous errors有效解决方式
  11. ubuntu创建wifi热点(android可识别)亲测可用
  12. IOS开发之XCode学习013:步进器和分栏控件
  13. 微信小程序(七)文章详情页面动态显示
  14. Linux分页机制之分页机制的实现详解--Linux内存管理(八)
  15. linux-网站收藏
  16. Prometheus监控学习记录
  17. Lintcode415-Valid Palindrome-Medium
  18. open()、fwrite()、fread()函数使用说明与示例
  19. js中获取事件对象的方法小结
  20. html----h1-6标签

热门文章

  1. EasyUI numbox输入框,金额格式化显示
  2. Windows Server 2008 远程桌面连接拒绝
  3. Kali 2.0安装与使用指南
  4. stylus使用文档总结:选择器+变量+插值+运算符+混合书写+方法
  5. [Python爬虫] 之二十八:Selenium +phantomjs 利用 pyquery抓取网站排名信息
  6. 如何使用angularjs实现表单验证
  7. 视频质量评价方法:VQM
  8. 让Vs2013 完美支持EF6.1 Code First with Oracle 2015年12月24日更新
  9. 基于SpringBoot的Environment源码理解实现分散配置
  10. Android 查看 无wifi/usb设备的logcat方法