Distant Galaxy

https://vjudge.net/problem/UVALive-3695

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

//left[i]表示x < i且位于边界的点数  on1[i]表示x = i且不包含上下边界的点数 on2[i]表示x = i且包含上下边界的点数
//对于选线i,j答案:left[j] - left[i] + on1[i] + on2[j]
//维护on1[i] - left[i]的最大值即可

两个特殊情况:只有一种x或只有一种y需要特判

我特判x的时候手残写成y调了很久。。。。。。。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
inline void swap(long long &a, long long &b)
{
long long tmp = a;a = b;b = tmp;
}
inline void read(long long &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const long long INF = 0x3f3f3f3f;
const long long MAXN = + ; long long x[MAXN], y[MAXN], cntx[MAXN], cnty[MAXN], left[MAXN], on1[MAXN], on2[MAXN], t, n, tot, ans; //left[i]表示x < i且位于边界的点数 on1[i]表示x = i且不包含上下边界的点数 on2[i]表示x = i且包含上下边界的点数
//对于选线i,j答案:left[j] - left[i] + on1[i] + on2[j]
//维护on1[i] - left[i]的最大值即可 bool cmp1(long long a, long long b)
{
return x[a] == x[b] ? y[a] < y[b] : x[a] < x[b];
} bool cmp2(long long a, long long b)
{
return y[a] == y[b] ? x[a] < x[b] : y[a] < y[b];
} int main()
{
while(scanf("%lld", &n) != EOF && n)
{
++ t;ans = ;
for(register long long i = ;i <= n;++ i) read(x[i]), read(y[i]), cntx[i] = cnty[i] = i;
std::sort(cntx + , cntx + + n, cmp1);
std::sort(cnty + , cnty + + n, cmp2);
if(y[cnty[]] == y[cnty[n]]) ans = n;
else
{
x[] = y[] = -,,,;
for(register long long i = ;i <= n;++ i)
{
if(y[cnty[i]] == y[cnty[i - ]]) continue;
for(register long long j = i + ;j <= n;++ j)
{
if(y[cnty[i]] == y[cnty[j]]) continue;
if(y[cnty[j]] == y[cnty[j - ]]) continue;
tot = ;
for(register long long k = ;k <= n;++ k)
{
if(k == || x[cntx[k]] != x[cntx[k - ]])
{
++ tot;
on1[tot] = on2[tot] = ;
left[tot] = tot == ? : left[tot - ] + on2[tot - ] - on1[tot - ];
}
if(y[cntx[k]] > y[cnty[i]] && y[cntx[k]] < y[cnty[j]]) ++ on1[tot];
if(y[cntx[k]] >= y[cnty[i]] && y[cntx[k]] <= y[cnty[j]]) ++ on2[tot];
}
if(tot <= )
{
ans = n;
break;
}
long long mi = ;
for(long long j = ;j <= tot;++ j)
{
ans = max(ans, mi + left[j] + on2[j]);
mi = max(mi, on1[j] - left[j]);
}
}
}
}
printf("Case %lld: %lld\n", t, ans);
}
return ;
}

LA3695

最新文章

  1. HTML 30分钟入门教程
  2. [转] 使用 MYSQLBINLOG 来恢复数据
  3. CF722D. Generating Sets[贪心 STL]
  4. [翻译]Shape comparison language
  5. SSL连接建立过程分析(1)
  6. EasyUI中combotree允许多选的时候onSelect事件会重复触发onCheck事件
  7. searchbar的使用介绍
  8. 聊一聊我们都熟知的 “ Java分层 ”
  9. 微软Telnet的回显功能开启
  10. Html5 &lt;video&gt;实现摄像头监控问题:html5并不支持rtsp协议,所以使用vlc进行转码,将rtsp转http流,这样&lt;video&gt;才可以直接播放
  11. web自动化上传附件 2
  12. Day 6-2简单的socket通信
  13. docker启动容器报错: could not synchronise with container process: not a directory
  14. Python新手入门英文词汇(1-1)
  15. 创建spark_读取数据
  16. 自动化测试-7.selenium定位一组对象
  17. python第三十一课--递归(1.简单递归函数的定义和使用)
  18. 【转】 Android常用实例—Alert Dialog的使用
  19. 阿里云容器服务区块链解决方案全新升级 支持Hyperledger Fabric v1.1
  20. map-reduce 优化

热门文章

  1. 在core2.0中实现按程序集注入依赖
  2. java_缓冲流(文件内容排序)
  3. (转)linux centos 编译luabind-0.9.1 动态库 静态库
  4. 那些使用VSCode写Python踩过的坑(Anaconda配置)
  5. Aria2 使用
  6. js 手机号加密 中间星号表示
  7. 扩展IEnumerable&lt;T&gt; ForEach()方法
  8. java使用stream流批量读取并合并文件,避免File相关类导致单文件过大造成的内存溢出。
  9. 2019牛客暑假多校赛(第二场) F和H(单调栈)
  10. JavaScript事件(随笔)