给出一些点的初始位置(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. ASP.NET页面刷新的实现方法总结

    先看看ASP.NET页面刷新的实现方法: 第一: private void Button1_Click( object sender, System.EventArgs e ) { Response. ...

  2. ubuntu安装后没有root密码

    新安装的ubuntu没有设置root密码,也就不能登录到root账户下.要想设置root密码需要在当前账户下输入sudo passwd,然后输入当前用户的密码,然后输入两次root的新密码,即可完成r ...

  3. Linux下ettercap的安装,make安装软件步骤

    第一步:下载ettercap的压缩包 用tar 解压压缩包,-z 用gzip的方式解压 -x 解打包/解压缩 -f 指定包  -v显示进度 ls 可以查看解压后出现一个新目录 ettercap-0.8 ...

  4. POJ 3685

    Matrix Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 4428   Accepted: 1102 Descriptio ...

  5. line-height 与垂直居中!

    在此之前,对于line-height 与垂直居中的问题,经常碰到. 比如,图片与span在同一个box中的时候,竟然会各种偏移.要想达到理想的效果真的是各种难. 有时间,决定认真的啃一啃. 一 lin ...

  6. x64的调用约定

    在设计调用约定时,x64 体系结构利用机会清除了现有 Win32 调用约定(如 __stdcall.__cdecl.__fastcall._thiscall 等)的混乱.在 Win64 中,只有一个本 ...

  7. linux下关于gz和bz2压缩格式的常用操作技巧

    .gz和.bz2都是linux下压缩文件的格式,有点类似windows下的.zip和.rar文件..bz2和.gz的区别在于,前者比后者压缩率更高,后者比前者花费更少的时间. 也就是说同一个文件,压缩 ...

  8. MongoDB (七) MongoDB 数据类型

    MongoDB支持许多数据类型的列表下面给出: String : 这是最常用的数据类型来存储数据.在MongoDB中的字符串必须是有效的UTF-8. Integer : 这种类型是用来存储一个数值.整 ...

  9. 李洪强iOS开发之- 实现简单的弹窗

     李洪强iOS开发之- 实现简单的弹窗 实现的效果:  112222222222223333333333333333

  10. java隐士类型转换和强制类型转换

    ,byte和short型在计算时会自动转换为int型计算,结果也是int 型.所以a1*a2的结果是int 型的. byte+byte=int,低级向高级是隐式类型转换,高级向低级必须强制类型转换,b ...