LA3695 Distant Galaxy
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的更多相关文章
- hdu Distant Galaxy(遥远的银河)
Distant Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 【poj3141】 Distant Galaxy
http://poj.org/problem?id=3141 (题目链接) 题意 给出平面上n个点,找出一个矩形,使边界上包含尽量多的点. solution 不难发现,除非所有输入点都在同一行或同一列 ...
- uva 1382 - Distant Galaxy
题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=91208#problem/G 题意: 给出平面上的n个点,找出一个矩形,使得边 ...
- LA 3695 Distant Galaxy
给出n个点的坐标(坐标均为正数),求最多有多少点能同在一个矩形的边界上. 题解里是构造了这样的几个数组,图中表示的很明白了. 首先枚举两条水平线,然后left[i]表示竖线i左边位于水平线上的点,on ...
- 【巧妙预处理系列+离散化处理】【uva1382】Distant Galaxy
给出平面上的n个点,找一个矩形,使得边界上包含尽量多的点. [输入格式] 输入的第一行为数据组数T.每组数据的第一行为整数n(1≤n≤100):以下n行每行两个整数,即各个点的坐标(坐标均为绝对值不超 ...
- UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【UVALive】3695 Distant Galaxy(......)
题目 传送门:QWQ 分析 好喵啊~~~~ 不会做 正解看蓝书P53吧 代码 #include <cstdio> #include <algorithm> using name ...
- UVALive - 3695 Distant Galaxy
InputThere are multiple test cases in the input file. Each test case starts with one integer N, (1 ≤ ...
- UVaLive 3695 Distant Galaxy (扫描线)
题意:给平面上的 n 个点,找出一个矩形,使得边界上包含尽量多的点. 析:如果暴力那么就是枚举上下边界,左右边界,还得统计个数,时间复杂度太高,所以我们考虑用扫描线来做,枚举上下边界, 然后用其他方法 ...
随机推荐
- 19.SimLogin_case08
# 模拟登录微博 import time import base64 import rsa import binascii import requests import re import rando ...
- 多边形游戏 /// 区间DP oj1903
题目大意: ... Input 输入的第一行是单独一个整数n( 3 ≤ n ≤ 18 ),表示多边形的顶点数(同时也是边数). 接下来第n行,每行包含一个运算符("+"或" ...
- ASCII专用测试字符串
这段是废话: 在很多时候不同语言所写的不同终端中 经常会有字符串转码的问题 常用一下字符串测试不同终端的输出可以快速匹配和修改默认转码 正文: !""""#$% ...
- python类的静态方法和类方法区别
先看语法,python 类语法中有三种方法,实例方法,静态方法,类方法. # coding:utf-8 class Foo(object): """类三种方法语法形式&q ...
- 高效开发 Dubbo?用 Spring Boot 可得劲!
不仅简化了 Dubbo 基于 xml 配置的方式,也提高了日常开发效率,甚至提升了工作幸福感. 为了节省亲爱的读者您的时间,请根据以下2点提示来阅读本文,以提高您的阅读收获效率哦. 如果您只有简单的 ...
- varStatus实现<c:forEach获取元素的下标 集合长度
有时候需要获取元素的下标,来实现一个编号的效果 那么使用 varStatus可以实现 代码 效果 如果需要把序号倒着数 那就用集合的长度减去当前下标 首先引入 <%@ taglib prefix ...
- java线程池的使用学习
目录 1. 线程池的创建 2. 线程池的运行规则 3. 线程池的关闭 4. 线程池的使用场合 5. 线程池大小的设置 6 实现举例 1. 线程池的创建 线程池的创建使用ThreadPoolExecut ...
- python-web-习题
1.简单描述 webbrowser.requests.BeautifulSoup 和 selenium 模块之间的不同 webbrowser模块有一个 open() 方法,它启动 web 浏览器,打开 ...
- mapduce简介
原文引自:http://www.cnblogs.com/shishanyuan/p/4639519.html 1.环境说明 部署节点操作系统为CentOS,防火墙和SElinux禁用,创建了一个shi ...
- osg::BlendFunc来设置透明度
osg::BlendFunc介绍 混合是什么呢?混合就是把两种颜色混在一起.具体一点,就是把某一像素位置原来的颜色和将要画上去的颜色,通过某种方式混在一起,从而实现特殊的效果. 假设我们需要 ...