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. 《程序员代码面试指南》第八章 数组和矩阵问题 找到无序数组中最小的k 个数

    题目 找到无序数组中最小的k 个数 java代码 package com.lizhouwei.chapter8; /** * @Description: 找到无序数组中最小的k 个数 * @Autho ...

  2. ES6中的class 与prototype

    一.定义构造函数 在以前的js中,生成一个对象实例,需要先定义构造函数,然后通过prototype 的方式来添加方法,在生成实例: function Person(){ this.name = &qu ...

  3. Windows Server 2008 MS Office 操作 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问。 (异常来自 HRESULT:0x80070005 (E_ACCESSDENIED))。

    Make sure that you have Office runtime installed on the server. If you are using Windows Server 2008 ...

  4. 使用diff制作补丁【学习笔记】

    源文件:main.c #include <stdio.h> int main() { printf("hello"); } 修改之后的文件: main1.c #incl ...

  5. JavaScript中双叹号(!!)作用示例介绍

    http://www.jb51.net/article/48881.htm 经常看到这样的例子: var a: var b=!!a; a默认是undefined.!a是true,!!a则是false, ...

  6. matlab之细胞数组

    学习matlab的一个博客:https://blog.csdn.net/smf0504/article/details/51814362 Matlab从5.0版开始引入了一种新的数据类型—细胞( ce ...

  7. 使用 HTML5 的 IndexedDB API

    1. [代码]判断是否支持 IndexedDB     var indexedDB = window.indexedDB || window.webkitIndexedDB || window.moz ...

  8. BZOJ 1207 [HNOI2004]打鼹鼠:dp【类似最长上升子序列】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1207 题意: 有一个n*n的网格,接下来一段时间内会有m只鼹鼠出现. 第i只鼹鼠会在tim ...

  9. PHP之面向对象PHP之面向对象(面向对象是什么)

    PHP之面向对象(面向对象是什么) 一.总结 一句话总结: 面向对象就是类:类都要 属性 和 方法 比如人:属性比如身高体重,方法比如吃饭喝水 面向对象中 ,方法即是函数 : 属性即是变量 ,只是面相 ...

  10. html5--1.19 通用属性

    html5--1.19 通用属性 学习要点: 1.通用属性的概念及几个常用的通用属性2.对属性值的若干点补充 通用属性 通用属性(全局属性)可以用于任何的HTML5元素:通用属性有十几种:这节课不会全 ...