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

LA3695 Distant Galaxy的更多相关文章

  1. hdu Distant Galaxy(遥远的银河)

    Distant Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. 【poj3141】 Distant Galaxy

    http://poj.org/problem?id=3141 (题目链接) 题意 给出平面上n个点,找出一个矩形,使边界上包含尽量多的点. solution 不难发现,除非所有输入点都在同一行或同一列 ...

  3. uva 1382 - Distant Galaxy

    题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=91208#problem/G 题意:  给出平面上的n个点,找出一个矩形,使得边 ...

  4. LA 3695 Distant Galaxy

    给出n个点的坐标(坐标均为正数),求最多有多少点能同在一个矩形的边界上. 题解里是构造了这样的几个数组,图中表示的很明白了. 首先枚举两条水平线,然后left[i]表示竖线i左边位于水平线上的点,on ...

  5. 【巧妙预处理系列+离散化处理】【uva1382】Distant Galaxy

    给出平面上的n个点,找一个矩形,使得边界上包含尽量多的点. [输入格式] 输入的第一行为数据组数T.每组数据的第一行为整数n(1≤n≤100):以下n行每行两个整数,即各个点的坐标(坐标均为绝对值不超 ...

  6. UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. 【UVALive】3695 Distant Galaxy(......)

    题目 传送门:QWQ 分析 好喵啊~~~~ 不会做 正解看蓝书P53吧 代码 #include <cstdio> #include <algorithm> using name ...

  8. UVALive - 3695 Distant Galaxy

    InputThere are multiple test cases in the input file. Each test case starts with one integer N, (1 ≤ ...

  9. UVaLive 3695 Distant Galaxy (扫描线)

    题意:给平面上的 n 个点,找出一个矩形,使得边界上包含尽量多的点. 析:如果暴力那么就是枚举上下边界,左右边界,还得统计个数,时间复杂度太高,所以我们考虑用扫描线来做,枚举上下边界, 然后用其他方法 ...

随机推荐

  1. <Django> 高级(其他知识点)

    1. 管理静态文件 什么是静态文件? 项目中的CSS.图片.js都是静态文件 配置静态文件(settings.py) # Static files (CSS, JavaScript, Images) ...

  2. Java核心-02 Exception和Error有什么区别?

    今天我要问你的问题是,请对比 Exception 和 Error,另外,运行时异常与一般异常有什么区别? 典型回答 Exception 和 Error 都是继承了 Throwable 类,在 Java ...

  3. 编程之法:面试和算法心得(寻找最小的k个数)

    内容全部来自编程之法:面试和算法心得一书,实现是自己写的使用的是java 题目描述 输入n个整数,输出其中最小的k个. 分析与解法 解法一 要求一个序列中最小的k个数,按照惯有的思维方式,则是先对这个 ...

  4. ON_WM_TIMER() void (__cdecl xx::* )(UINT)”转换为“void (__cdecl CWnd::* )(UINT_PTR)

     ON_WM_TIMER()在编译器从32位转换为64位的时候, 出现的问题; class CFlatComboBox : public CComboBox   (基类为CWnd) 为了重载CWnd的 ...

  5. CNN网络中的不变性理解

    神经网络中的不变性 原文:https://blog.csdn.net/voxel_grid/article/details/79275637     个人认为cnn中conv层对应的是“等变性”(Eq ...

  6. web.xml中多个Servlet执行顺序的问题!

    1.两个servlet或者两个servlet-mapping,其中的servlet-name名称不能存在相同. 2.所有的servlet-mapping标签下,url-pattern中包含的文本不能相 ...

  7. 小程序怎样控制rich-text中的<img>标签自适应

    小程序通过rich-text实现字符串转化为html,即 <rich-text node="{{html}}"></rich-text>.如果html字符串 ...

  8. DuiLib学习笔记3.颜色探究

    在前面两篇日志已经能使用xml了.今天准备好好的折腾一番,结果在颜色上却掉坑里了. 起初我在ps里取颜色为0104ff 这里01为R,04为G,ff为B 在控件的属性里有这样一个属性bkcolor=& ...

  9. js获取base64格式图片预览上传并用php保存到本地服务器指定文件夹

    html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  10. 2019/10/9 CSP-S 模拟测

    T1:最大约数和 给定一个正整数 S,现在要求你选出若干个互不相同的正整数,使得它们的和不大于 S,而且每个数的因数(不包括本身)之和最大.S <= 1000 分析: 其实考完才听他们说是背包, ...