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. 在IIS中某一个网站启用net.tcp

    绑定 高级设置  http和net.tcp用逗号分隔 //擦擦擦,见鬼了,下面的是tcp.net导致我找了好久,都找不出这个错误 //一定要注意,不要写错了. 否则会收到提示:找不到具有绑定 NetT ...

  2. 利用javascript动态向网页中添加表格

    效果图如下: 以下是代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  3. React之jsx语法特性

    jsx 语法,直接可以在js中使用html标签. 还可以通过花括号的形式,在html标签中,写js表达式. <div> { 1 + 2 } hello,world! </div> ...

  4. Linux_服务器_03_xxx is not in the sudoers file.This incident will be reported.的解决方法

    1.切换到root用户下,怎么切换就不用说了吧,不会的自己百度去. 2.添加sudo文件的写权限,命令是:chmod u+w /etc/sudoers 3.编辑sudoers文件vi /etc/sud ...

  5. 初入 CLR - 阅读《CLR via C#》笔记

    最近买了一本书<CLR via C#>阅读了第一章 - CLR 的执行模型,对 .NET 一直提到的 CLR 和 .NET Framework 有了一个大致的了解.我理解主要体现在: ■ ...

  6. 四连测Day4

    四连爆炸 卡我常数 好像被AluminumGod拉到了创客...哇我这个天天爆炸的水平可能会被其他三位dalao吊起来打 orz Edmond-Karp_XiongGod orz Deidara_Wa ...

  7. java-04 数组和二维数组

    java 中内存分配地址值以及栈和堆得区别: ##########数组操作的两个常见小问题(越界和空指针)############## 数组索引越界异常,访问了不存在的索引: 空指针: ####### ...

  8. RPM包构建

    参考资料 https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html-single/RPM_Guide/i ...

  9. 四维偏序 CDQ套CDQ

    对CDQ深一步的理解 昨天做了一道CDQ,看了一堆CDQ可做的题,今天又做了一道四维偏序 感觉对CDQ的理解又深了一点,故来写一写现在自己对于CDQ的理解 CDQ其实就是实现了这样的一个问题的转化: ...

  10. windwos 10 谷歌浏览器出现彩色闪条

    应该是上个星期五开始,发现电脑从别的地方切换到谷歌浏览器就会出现闪条,开始也没太注意,但是到周一还是这样,所以再网上查了下, 说什么的都有,什么你按脑屏幕坏了,内存条不行什么是的.后来才发现原来是谷歌 ...