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. 二分图最佳匹配KM算法 /// 牛客暑期第五场E

    题目大意: 给定n,有n间宿舍 每间4人 接下来n行 是第一年学校规定的宿舍安排 接下来n行 是第二年学生的宿舍安排意愿 求满足学生意愿的最少交换次数 input 2 1 2 3 4 5 6 7 8 ...

  2. java_DateTimeFormatter

    日期时间的格式化和解析: public class DateTimeFormatterTest { /** * 时间日期格式化 * @param args */ public static void ...

  3. 一个WordCount执行过程的实例

  4. nodejs入门最简单例子

    一.mac话,先安装nodejs环境: brew install nodejs 二.先写一个main.js var http = require("http"); http.cre ...

  5. JS流程控制语句 反反复复(while循环) 和for循环有相同功能的还有while循环, while循环重复执行一段代码,直到某个条件不再满足。

    反反复复(while循环) 和for循环有相同功能的还有while循环, while循环重复执行一段代码,直到某个条件不再满足. while语句结构: while(判断条件) { 循环语句 } 使用w ...

  6. linux普通用户无法登录mysql

    一.前言 本帖方法只适用于普通用户无法登录,但root用户可以登录的情况. 今天将war包放入linux后,运行报错,经过检查发现是数据库连接不上.奇怪的是,用户名和密码都是正确的,所以有了以下发现. ...

  7. Matlab神经网络验证码识别

    本文,将会简述如何利用Matlab的强大功能,调用神经网络处理验证码的识别问题.  预备知识,Matlab基础编程,神经网络基础.  可以先看下: Matlab基础视频教程 Matlab经典教程--从 ...

  8. Android开发 ExpandableListView 可折叠列表详解

    前言 在需要实现一个List的item需要包含列表的时候,我们就可以选择ExpandableListView. 其实这个View的原始设计还是ListView的那套.就是增加2层的ListView而已 ...

  9. Atcoder arc085

    C:HSI 期望模型,不想说. #include<cstdio> using namespace std; typedef long long ll; int main() { int n ...

  10. python网络框架Twisted

    什么是Twisted Twisted是一个用python语言写的事件驱动网络框架,它支持很多种协议,包括UDP,TCP,TLS和其他应用层协议,比如HTTP,SMTP,NNTM,IRC,XMPP/Ja ...