LA 3905 Meteor
给出一些点的初始位置(x, y)及速度(a, b)和一个矩形框,求能同时出现在矩形框内部的点数的最大值。
把每个点进出矩形的时刻分别看做一个事件,则每个点可能对应两个事件,进入事件和离开事件。
按这些事件的发生时间进行排序,然后逐个扫描,遇到进入事件cnt++,遇到离开事件--cnt,用ans记录cnt的最大值。
对时间相同情况的处理,当一个进入事件的时刻和离开事件的时刻相同时,应该先处理离开事件后处理进入事件。
因为速度(a, b)是-10~10的整数,所以乘以LCM(1,2,3,,,10) = 2520,可避免浮点数的运算。
后来我还在纳闷t≥0的条件是如何限制的,后来明白因为L的初值为0,所以max(L, t)是不会出现负数的情况的。
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
const int LCM = ; struct Event
{
int x;
int type;
bool operator < (const Event a) const
{
return x < a.x || (x == a.x && type > a.type);
}
}events[maxn * ]; void update(int x, int a, int w, int &L, int &R)
{//0<x+at<w
if(a == )
{
if(x <= || x >= w)
R = L - ;
}
else if(a > )
{
L = max(L, -x*LCM/a);
R = min(R, (w-x)*LCM/a);
}
else
{
L = max(L, (w-x)*LCM/a);
R = min(R, -x*LCM/a);
}
} int main(void)
{
#ifdef LOCAL
freopen("3905in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int w, h, n, e = ;
scanf("%d%d%d", &w, &h, &n);
for(int i = ; i < n; ++i)
{
int x, y, a, b;
scanf("%d%d%d%d", &x, &y, &a, &b);
int L = , R = (int)1e9;
update(x, a, w, L, R);
update(y, b, h, L ,R);
if(L < R)
{
events[e].x = L; //左端点事件
events[e++].type = ;
events[e].x = R;
events[e++].type = ;
}
}
sort(events, events + e);
int cnt = , ans = ;
for(int i = ; i < e; ++i)
{
if(events[i].type == )
ans = max(ans, ++cnt);
else
--cnt;
}
printf("%d\n", ans);
}
return ;
}
代码君
LA 3905 Meteor的更多相关文章
- LA 3905 Meteor 扫描线
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
- 3905 - Meteor
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
- 【UVALive】3905 Meteor(扫描线)
题目 传送门:QWQ 分析 扫描线搞一搞. 按左端点排序,左端点相同时按右端点排序. 如果是左端点就$ cnt++ $,否则$ cnt-- $ 统计一下$ Max $就行了 代码 #include & ...
- UVaLive 3905 Meteor (扫描线)
题意:给定上一个矩形照相机和 n 个流星,问你照相机最多能拍到多少个流星. 析:直接看,似乎很难解决,我们换一个思路,我们认为流星的轨迹就没有用的,我们可以记录每个流星每个流星在照相机中出现的时间段, ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...
- 【译】Meteor 新手教程:在排行榜上添加新特性
原文:http://danneu.com/posts/6-meteor-tutorial-for-fellow-noobs-adding-features-to-the-leaderboard-dem ...
- Using View and Data API with Meteor
By Daniel Du I have been studying Meteor these days, and find that Meteor is really a mind-blowing f ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
随机推荐
- cache应用(asp.net 2.0 SQL数据缓存依赖 [SqlCacheDependency ] )
Asp.net 2.0 提供了一个新的数据缓存功能,就是利用sql server2005 的异步通知功能来实现缓存 1.首先在sqlserver2005 中创建一个test的数据库. 在SQL Ser ...
- Linux下ettercap的安装,make安装软件步骤
第一步:下载ettercap的压缩包 用tar 解压压缩包,-z 用gzip的方式解压 -x 解打包/解压缩 -f 指定包 -v显示进度 ls 可以查看解压后出现一个新目录 ettercap-0.8 ...
- Python - 装饰器使用过程中的误区
曾灵敏 - APRIL 27, 2015 装饰器基本概念 大家都知道装饰器是一个很著名的设计模式,经常被用于AOP(面向切面编程)的场景,较为经典的有插入日志,性能测试,事务处理,Web权限校验, C ...
- LA 3713
The Bandulu Space Agency (BSA) has plans for the following three space missions: Mission A: Landing ...
- Install WindowBuilder for Eclipse
WindowBuilder官方下载安装说明地址:http://www.eclipse.org/windowbuilder/download.php 先祝各位能顺利安装上!以下是基于Eclipse in ...
- Razor视图引擎 语法学习(一)
ASP.NET MVC是一种构建web应用程序的框架,它将一般的MVC(Model-View-Controller)模式应用于ASP.NET框架: ASP.NET约定优于配置:基本分为模型(对实体数据 ...
- ios下划线变量:为什么变量前要加下划线才有用?
先看一段代码. 复制代码 appdelegate.h @property (weak) IBOutlet NSMatrix *StockType; @property (weak) IBOutle ...
- Spring框架学习之第7节
配置Bean的细节 ☞尽量使用scope=”singleton”,不要使用prototype,因为这样对我们的性能影响较大 ②如何给集合类型注入值 Java中主要的map,set,list / 数组 ...
- 289. Game of Life
题目: According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a ce ...
- Hadoop namenode无法启动问题解决
原因:在root账户(非hadoop账户)下操作hadoop会导致很大的问题 首先运行bin/start-all.sh发现namenode没有启动 只有它们 9428 DataNode 9712 Jo ...