UVALive - 3695 Distant Galaxy
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的更多相关文章
- UVaLive 3695 Distant Galaxy (扫描线)
题意:给平面上的 n 个点,找出一个矩形,使得边界上包含尽量多的点. 析:如果暴力那么就是枚举上下边界,左右边界,还得统计个数,时间复杂度太高,所以我们考虑用扫描线来做,枚举上下边界, 然后用其他方法 ...
- 【UVALive】3695 Distant Galaxy(......)
题目 传送门:QWQ 分析 好喵啊~~~~ 不会做 正解看蓝书P53吧 代码 #include <cstdio> #include <algorithm> using name ...
- LA 3695 Distant Galaxy
给出n个点的坐标(坐标均为正数),求最多有多少点能同在一个矩形的边界上. 题解里是构造了这样的几个数组,图中表示的很明白了. 首先枚举两条水平线,然后left[i]表示竖线i左边位于水平线上的点,on ...
- UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- hdu Distant Galaxy(遥远的银河)
Distant Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- LA3695 Distant Galaxy
Distant Galaxy https://vjudge.net/problem/UVALive-3695 You are observing a distant galaxy using a te ...
- 【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个点,找出一个矩形,使得边 ...
- 【巧妙预处理系列+离散化处理】【uva1382】Distant Galaxy
给出平面上的n个点,找一个矩形,使得边界上包含尽量多的点. [输入格式] 输入的第一行为数据组数T.每组数据的第一行为整数n(1≤n≤100):以下n行每行两个整数,即各个点的坐标(坐标均为绝对值不超 ...
随机推荐
- 5.JavaScript优化及导航菜单背后的秘密
JavaScript优化及导航菜单背后的秘密 伍星 学习目标1.进一步了解前端优化 学习如何编写良好的 JavaScirpt2.通过导航的学习,了解JavaScirpt的应用 JavaScript在用 ...
- dojo 官方翻译 dojo/string 版本1.10
官方地址:http://dojotoolkit.org/reference-guide/1.10/dojo/string.html#dojo-string require(["dojo/st ...
- 郝健: Linux内存管理学习笔记-第1节课【转】
本文转载自:https://blog.csdn.net/juS3Ve/article/details/80035751 摘要 MMU与分页机制 内存区域(内存分ZONE) LinuxBuddy分配算法 ...
- 算法(Algorithms)第4版 练习 1.3.15
Queue: package com.qiusongde; import java.util.Iterator; import java.util.NoSuchElementException; im ...
- iOS Assertion failure in -[UITableView _classicHeightForRowAtIndexPath:]
Assertion failure in -[UITableView _classicHeightForRowAtIndexPath:], /SourceCache/UIKit_Sim/UIKit-3 ...
- Centos7 安装lnmp
Centos7 安装lnmp 1.下载 wget http://soft.vpser.net/lnmp/lnmp1.5-full.tar.gz 2.解压 tar -zvxf lnmp1.5-full. ...
- 【C】四则运算生成和核对器----by郁卓、谢明浩
[Github项目地址] 完成功能: 1. 使用 -n 参数控制生成题目的个数 2. 使用 -r 参数控制题目中数值(自然数.真分数和真分数分母)的范围 3. 生成的题目中计算过程不能产生负数,也就是 ...
- L91
Make Healthy Choices Easier Options Telling people to change unhealthy behaviors doesn't work. Other ...
- DBSCAN 聚类分析
DBSCANCLUSTER DBSCAN(Density-basedspatial clustering ofapplications with noise)Martin.Ester, Hans-Pe ...
- Dubbo配置设计
配置分类 配置格式 配置加载 可编程配置 配置缺省值 配置一致性 配置覆盖 配置继承 配置向后兼容 配置分类 首先,配置的用途是有多种的,大致可以分为: 环境配置,比如:连接数,超时等配置. 描述配置 ...