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
10 9 , 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

看到乱序的点应该想到排序,上下边界确定后,横向扫应该想到递推,时间复杂度为O(N^3)

#include <cstdio>
#include <algorithm>
#include <iostream> #define N 101 int Left[N], on[N], on2[N], y[N], n, ans, kase = ; struct Point {
int x, y; bool operator<(const Point &rhs) const {
return x <= rhs.x;
}
} P[N]; int solve(); using namespace std; int main() {
while (cin >> n && n) {
for (int i = ; i < n; ++i) {
cin >> P[i].x >> P[i].y;
y[i] = P[i].y;
}
printf("Case %d: %d\n", ++kase, solve());
} } int solve() {
ans = , sort(P, P + n), sort(y, y + n);
int m = unique(y, y + n) - y;
if (m <= )
return n;
for (int i = ; i < m; ++i) {
for (int j = i + ; j < m; ++j) { //确定上下边界
int y1 = y[i], y2 = y[j], k = , t = , M = ; for (; t < n; ++t) { //预扫描,递推获得left,on,on2数组的值
if (t == || P[t].x != P[t - ].x) {
k++;
on[k] = on2[k] = ;
Left[k] = Left[k - ] + on2[k - ] - on[k - ];
}
if (y1 < P[t].y && P[t].y < y2) //c++是不让连写的
on[k]++;
if (y1 <= P[t].y && P[t].y <= y2)
on2[k]++;
}
for (t = ; t <= k; ++t) {
ans = max(on2[t] + Left[t] + M, ans);
M = max(on[t] - Left[t], M);
}
}
}
return ans;
}

UVALive - 3695 Distant Galaxy的更多相关文章

  1. UVaLive 3695 Distant Galaxy (扫描线)

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

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

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

  3. LA 3695 Distant Galaxy

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

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

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

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

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

  6. LA3695 Distant Galaxy

    Distant Galaxy https://vjudge.net/problem/UVALive-3695 You are observing a distant galaxy using a te ...

  7. 【poj3141】 Distant Galaxy

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

  8. uva 1382 - Distant Galaxy

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

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

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

随机推荐

  1. VC DLL方法的__declspec导入导出

    https://msdn.microsoft.com/zh-cn/library/a90k134d.aspx https://msdn.microsoft.com/zh-cn/library/ms23 ...

  2. hadoop 安装配置

    1.伪分布式搭建: 步骤参考: http://wenku.baidu.com/link?url=N_Sc7dqaO5HB47SmhntYZQI2tvvAjYt0mWT0fx28FDSMRYKTLUTc ...

  3. 简单的可兼容所有浏览器的操作html元素的javascript框架

    1.根据id名称取元素  $id(idName) 2.根据class定义取元素  $class(className)返回所有class被定义成className的元素数组,或者$Eclass(clas ...

  4. CSS3实现自定义Checkbox动画

    CSS3实现自定义Checkbox动画是一款CSS3自定义checkbox,而且这款checkbox还带有动画效果,当你选中checkbox的时候,会以动画的方式打上一个大大的勾. 源码下载:http ...

  5. java 创建 HMAC 签名

    ava 创建 HMAC 签名 psd素材 1. []ComputopTest.java package com.javaonly.hmac.test; import java.io.IOExcepti ...

  6. HDU 1850 Being a Good Boy in Spring Festival(博弈·Nim游戏)

    Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32 ...

  7. redis持久化的方式RDB 和 AOF

    redis持久化的方式RDB 和 AOF 一.对Redis持久化的探讨与理解 目前Redis持久化的方式有两种: RDB 和 AOF 首先,我们应该明确持久化的数据有什么用,答案是用于重启后的数据恢复 ...

  8. sed根据关键字注释crontab的计划任务

    [root@linux06 ~]# crontab -e*/5 * * * * /root/time_test.sh ----------------------------------------- ...

  9. HDU6118:度度熊的交易计划(入门级最小费用可行流)

    度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生产能力的区别,第i个片区能够花费a[i]元生产1个商品,但 ...

  10. c ++ auto 的使用

    该文转自:https://www.cnblogs.com/KunLunSu/p/7861330.html C++98 auto 早在C++98标准中就存在了auto关键字,那时的auto用于声明变量为 ...