给出一些点的初始位置(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的更多相关文章

  1. LA 3905 Meteor 扫描线

    The famous Korean internet company nhn has provided an internet-based photo service which allows The ...

  2. 3905 - Meteor

    The famous Korean internet company nhn has provided an internet-based photo service which allows The ...

  3. 【UVALive】3905 Meteor(扫描线)

    题目 传送门:QWQ 分析 扫描线搞一搞. 按左端点排序,左端点相同时按右端点排序. 如果是左端点就$ cnt++ $,否则$ cnt-- $ 统计一下$ Max $就行了 代码 #include & ...

  4. UVaLive 3905 Meteor (扫描线)

    题意:给定上一个矩形照相机和 n 个流星,问你照相机最多能拍到多少个流星. 析:直接看,似乎很难解决,我们换一个思路,我们认为流星的轨迹就没有用的,我们可以记录每个流星每个流星在照相机中出现的时间段, ...

  5. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  6. 【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 ...

  7. 【译】Meteor 新手教程:在排行榜上添加新特性

    原文:http://danneu.com/posts/6-meteor-tutorial-for-fellow-noobs-adding-features-to-the-leaderboard-dem ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Unity Texture 2D Compress

    测试了一下 unity 图片 对 apk 的影响. 上两种测试环境    1024 * 1024     带 alpha的话 默认压缩就是RBA 16bit就是2M     不带的话就是 etc 的话 ...

  2. Unity3D开发Windows Store应用程序 注意事项

    原地址:http://blog.csdn.net/jbjwpzyl3611421/article/details/12704491 针对最近在移植window store项目中遇到的问题,我整理了官方 ...

  3. spring mvc Controller与jquery Form表单提交代码demo

    1.JSP表单 <% String basePath = request.getScheme() + "://" + request.getServerName() +&qu ...

  4. Sql注入一种dump所有数据的方法

    Select exp(~(select*from(select(concat(@:=0,(select count(*)from`information_schema`.columns where t ...

  5. 如何开启Centos6.4系统的SSH服务

    无论是Centos6.4系统的虚拟电脑还是服务器,始终感觉直接在命令行中操作不方便:比如全选.复制.粘贴.翻页等等.比如服务器就需要在机房给服务器接上显示器.键盘才操作感觉更麻烦.所以就可借助SSH( ...

  6. mq_send

    NAME mq_send - 将消息发送到消息队列 (REALTIME) SYNOPSIS #include <mqueue.h>int mq_send(mqd_t mqdes, cons ...

  7. Keil 4.7a版本问题&Jlink Clone问题

    听PP说Keil 4.7A新出,支持代码自动补全.激动之至,keil官网急填,下载安装.  问题即刻遇见①,电脑蓝屏,安装包损坏.当下载安装包未下载完时,续传安装包没用了.还是重下载吧,免得浪费时间. ...

  8. MAC终端配色Solarized

    MAC终端配色Solarized $ git clone git://github.com/altercation/solarized.git 在 solarized/osx-terminal.app ...

  9. mybaits3.2.8 别名包扫描通配符

    <mybatis.version>3.2.8</mybatis.version><mybatis.spring.version>1.2.2</mybatis. ...

  10. java读写中文文件

    在用Java程序进行读写含中文的txt文件时,经常会出现读出或写入的内容会出现乱码.原因其实很简单,就是系统的编码和程序的编码采用了不同的编码格式.通常,假如自己不修改的话,windows自身采用的编 ...