UVaLive 3695 Distant Galaxy (扫描线)
题意:给平面上的 n 个点,找出一个矩形,使得边界上包含尽量多的点。
析:如果暴力那么就是枚举上下边界,左右边界,还得统计个数,时间复杂度太高,所以我们考虑用扫描线来做,枚举上下边界,
然后用其他方法来确定左右边界。我们定义left[i] 表示竖线左边位于上下边界上的点数(不包含在竖线上的点),on[i]表示竖线 i 上的点,
但不包含上下边界上的点,in[i]表示竖线 i 的上的点,但是包含上下边界上的点。那么我们可以递推。最后矩形边界上的点数为
left[i] - left[j] + on[i] + in[j],然后如果右边界 j 确定了,那么要 on[i] - in[i] 最大这个是不断更新 left[i] = left[i-1] + in[i-1] - on[i-1]。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} struct Point{
int x, y;
bool operator < (const Point &p) const{
return x < p.x;
}
};
Point a[maxn];
int l[maxn], on[maxn], in[maxn], y[maxn]; int solve(){
sort(a, a + n);
sort(y, y + n);
int ans = 0;
m = unique(y, y + n) - y;
if(m <= 2) return n; for(int y1 = 0; y1 < m; ++y1)
for(int y2 = y1 + 1; y2 < m; ++y2){
int k = 0;
for(int i = 0; i < n; ++i){
if(!i || a[i].x != a[i-1].x){
++k;
l[k] = !i ? 0 : l[k-1] + in[k-1] - on[k-1];
on[k] = in[k] = 0;
}
if(a[i].y > y[y1] && a[i].y < y[y2]) ++on[k];
if(a[i].y >= y[y1] && a[i].y <= y[y2]) ++in[k];
}
if(k <= 2) return n; int mmax = 0;
for(int i = 1; i <= k; ++i){
ans = max(ans, l[i] + in[i] + mmax);
mmax = max(mmax, on[i] - l[i]);
}
}
return ans;
} int main(){
int kase = 0;
while(scanf("%d", &n) == 1 && n){
for(int i = 0; i < n; ++i){
scanf("%d %d", &a[i].x, &a[i].y);
y[i] = a[i].y;
}
printf("Case %d: %d\n", ++kase, solve());
}
return 0;
}
UVaLive 3695 Distant Galaxy (扫描线)的更多相关文章
- 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(......)
题目 传送门:QWQ 分析 好喵啊~~~~ 不会做 正解看蓝书P53吧 代码 #include <cstdio> #include <algorithm> using name ...
- UVaLive 3695 City Game (扫描线)
题意:给定m*n的矩阵,有的是空地有的是墙,找出一个面积最大的子矩阵. 析:如果暴力,一定会超时的.我们可以使用扫描线,up[i][j] 表示从(i, j)向上可以到达的最高高度,left[i][j] ...
- 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 ...
- UVALive - 6864 Strange Antennas 扫描线
题目链接: http://acm.hust.edu.cn/vjudge/problem/87213 Strange Antennas Time Limit: 3000MS 题意 一个雷达能够辐射到的范 ...
- 【poj3141】 Distant Galaxy
http://poj.org/problem?id=3141 (题目链接) 题意 给出平面上n个点,找出一个矩形,使边界上包含尽量多的点. solution 不难发现,除非所有输入点都在同一行或同一列 ...
随机推荐
- 在XP上安装VS2002
在2002 年,随着 .NET 口号的提出与 Windows XP/Office XP 的公布,微软公布了 Visual Studio .NET(内部版本为 7.0). 使用VS2002+Object ...
- 51NOD 1962 区间计数 单调栈+二分 / 线段树+扫描线
区间计数 基准时间限制:1.5 秒 空间限制:262144 KB 分值: 80 两个数列 {An} , {Bn} ,请求出Ans, Ans定义如下: Ans:=Σni=1Σnj=i[max{ ...
- 【BZOJ3566】[SHOI2014]概率充电器 期望+树形DP
[BZOJ3566][SHOI2014]概率充电器 Description 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品——概率充电器:“采用全新纳米级加工技术,实现元件与导线 ...
- 网络摄像机IPCamera RTSP直播播放网络/权限/音视频数据/花屏问题检测与分析助手EasyRTSPClient
前言 最近在项目中遇到一个奇怪的问题,同样的SDK调用,访问海康摄像机的RTSP流,发保活OPTIONS命令保活,一个正常,而另一个一发就会被IPC断开,先看现场截图: 图1:发OPTIONS,摄像机 ...
- Javascript学习之三元运算符详解
本文主要是通过实例为大家介绍javascript三元运算符相关内容,希望对初学者学习这部分内容有所帮助. 实例 <!DOCTYPE html> <html> <head& ...
- Docker容器的数据卷(data volume),数据卷容器,数据卷的备份和还原。
Docker容器的数据卷(data volume),数据卷容器,数据卷的备份和还原. 数据卷就是数据(一个文件或者文件夹). Docker的理念之一是将应用与其运行的环境打包,docker容器的生命周 ...
- Java 符号引用 与 直接引用
在类的加载过程中的解析阶段,Java虚拟机会把类的二进制数据中的符号引用 替换为 直接引用,如Worker类中一个方法: public void gotoWork(){ car.run(); //这段 ...
- Vue中的methods、watch、computed
看到这个标题就知道这篇文章接下来要讲的内容,我们在使用vue的时候methods.watch.computed这三个特性一定经常使用,因为它们是非常的有用,但是没有彻底的理解它们的区别和各自的使用场景 ...
- Gym - 100187A A - Potion of Immortality —— 贪心
题目链接:http://codeforces.com/gym/100187/problem/A 题解: 光题意就想了很久:在最坏情况下的最小兔子数.其实就是至少用几只兔子就一定能找出仙药(答案存在的话 ...
- Memory Notification: Library Cache Object loaded into SGA
问题现象: 数据库服务器可以ping通,但SSH连接不了:应用.plsqldeveloper 也都连接不了.事情到了这个地步,只能重启服务器. 服务器环境:oracle10.2.0.1 +rhel5. ...