The famous Korean internet company nhn has provided an internet-based photo service which allows The famous Korean internet company users to directly take a photo of an astronomical phenomenon in space by controlling a high-performance telescope owned by nhn. A few days later, a meteoric shower, known as the biggest one in this century, is expected. nhn has announced a photo competition which awards the user who takes a photo containing as many meteors as possible by using the photo service. For this competition, nhn provides the information on the trajectories of the meteors at their web page in advance. The best way to win is to compute the moment (the time) at which the telescope can catch the maximum number of meteors.

You have n <tex2html_verbatim_mark>meteors, each moving in uniform linear motion; the meteor mi <tex2html_verbatim_mark>moves along the trajectory pi + t×vi<tex2html_verbatim_mark>over time t <tex2html_verbatim_mark>, where t <tex2html_verbatim_mark>is a non-negative real value, pi <tex2html_verbatim_mark>is the starting point of mi <tex2html_verbatim_mark>and vi <tex2html_verbatim_mark>is the velocity ofmi <tex2html_verbatim_mark>. The point pi = (xiyi) <tex2html_verbatim_mark>is represented by X <tex2html_verbatim_mark>-coordinate xi <tex2html_verbatim_mark>and Y <tex2html_verbatim_mark>-coordinate yi <tex2html_verbatim_mark>in the (XY) <tex2html_verbatim_mark>-plane, and the velocity vi = (aibi) <tex2html_verbatim_mark>is a non-zero vector with two components ai <tex2html_verbatim_mark>and bi <tex2html_verbatim_mark>in the (XY) <tex2html_verbatim_mark>-plane. For example, if pi = (1, 3) <tex2html_verbatim_mark>and vi = (-2, 5) <tex2html_verbatim_mark>, then the meteor mi <tex2html_verbatim_mark>will be at the position (0, 5.5) at time t = 0.5 <tex2html_verbatim_mark>because pi + t×vi = (1, 3) + 0.5×(-2, 5) = (0, 5.5) <tex2html_verbatim_mark>. The telescope has a rectangular frame with the lower-left corner (0, 0) and the upper-right corner (wh) <tex2html_verbatim_mark>. Refer to Figure 1. A meteor is said to be in the telescope frame if the meteor is in the interior of the frame (not on the boundary of the frame). For exam! ple, in Figure 1, p2p3p4 <tex2html_verbatim_mark>, and p5 <tex2html_verbatim_mark>cannot be taken by the telescope at any time because they do not pass the interior of the frame at all. You need to compute a time at which the number of meteors in the frame of the telescope is maximized, and then output the maximum number of meteors.

<tex2html_verbatim_mark>

Input

Your program is to read the input from standard input. The input consists of T <tex2html_verbatim_mark>test cases. The number of test cases T <tex2html_verbatim_mark>is given in the first line of the input. Each test case starts with a line containing two integers w<tex2html_verbatim_mark>and h <tex2html_verbatim_mark>(1wh100, 000) <tex2html_verbatim_mark>, the width and height of the telescope frame, which are separated by single space. The second line contains an integer n <tex2html_verbatim_mark>, the number of input points (meteors), 1n100, 000 <tex2html_verbatim_mark>. Each of the next n <tex2html_verbatim_mark>lines contain four integers xiyiai <tex2html_verbatim_mark>, and bi <tex2html_verbatim_mark>; (xiyi) <tex2html_verbatim_mark>is the starting point pi <tex2html_verbatim_mark>and (aibi) <tex2html_verbatim_mark>is the nonzero velocity vector vi <tex2html_verbatim_mark>of the i <tex2html_verbatim_mark>-th meteor; xi <tex2html_verbatim_mark>and yi <tex2html_verbatim_mark>are integer values between -200,000 and 200,000, and ai <tex2html_verbatim_mark>and bi <tex2html_verbatim_mark>are integer values between -10 and 10. Note that at least one of ai <tex2html_verbatim_mark>and bi <tex2html_verbatim_mark>is not zero. These four values are separated by single spaces. We assume that all starting points pi <tex2html_verbatim_mark>are distinct.

Output

Your program is to write to standard output. Print the maximum number of meteors which can be in the telescope frame at some moment.

Sample Input

2
4 2
2
-1 1 1 -1
5 2 -1 -1
13 6
7
3 -2 1 3
6 9 -2 -1
8 0 -1 -1
7 6 10 0
11 -2 2 1
-2 4 6 -1
3 2 -5 -1

Sample Output

1

2

题目大意:XOY坐标系上,给n个点(每个点的起始坐标跟速度),求在矩形区域最多能同时出现多少个点。

先把每个点在矩形上出现的时间段求出来(左右端点(左标记为0,右标记为1)push进vector容器,),二级排序。

从左只有处理各个端点,每遇到一个左端点,计数器加一;每遇到一个右端点,计数器减一。每次更新最大值。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std; const double eps=1e-;
double max(double a,double b){ return a-b>eps?a:b;}
double min(double a,double b){ return b-a>eps?a:b;} struct node
{
double x;
int i;
node(double x=,int i=):x(x),i(i){}
bool operator<(const node &A)const{
if(fabs(A.x-x)>eps) return x<A.x;
else return i>A.i;
}
};
int w,h,n;
vector<node> v; void update(int x,int a,int w,double &L,double &R)
{
if(a==)
{
if(x<= || x>=w) R=L-;
}
else if(a>)
{
L=max(L,-(double)x/a);
R=min(R,(double)(w-x)/a);
}
else
{
L=max(L,(double)(w-x)/a);
R=min(R,-(double)x/a);
}
} void Push()
{
int x,y,a,b;
scanf("%d %d %d %d",&x,&y,&a,&b);
double L=,R=1e9;
update(x,a,w,L,R);
update(y,b,h,L,R);
if(R-L>eps)//经过矩形的起止时间
{
v.push_back(node(L,));
v.push_back(node(R,));
}
} int main()
{
int T,i;
scanf("%d",&T);
while(T--)
{
v.clear();
scanf("%d %d %d",&w,&h,&n);
for(i=;i<n;i++) Push();
sort(v.begin(),v.end());
int cnt=,ans=;
for(i=;i<v.size();i++)
{
if(v[i].i==) ans=max(ans,++cnt);
else cnt--;
}
printf("%d\n",ans);
}
return ;
}

LA 3905 Meteor 扫描线的更多相关文章

  1. UVaLive 3905 Meteor (扫描线)

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

  2. LA 3905 Meteor

    给出一些点的初始位置(x, y)及速度(a, b)和一个矩形框,求能同时出现在矩形框内部的点数的最大值. 把每个点进出矩形的时刻分别看做一个事件,则每个点可能对应两个事件,进入事件和离开事件. 按这些 ...

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

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

  4. 3905 - Meteor

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

  5. ACM计算几何题目推荐

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

  6. 【转换模型+扫描线】【UVA1398】Meteor

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

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

  8. LA 3029 - City Game (简单扫描线)

    题目链接 题意:给一个m*n的矩阵, 其中一些格子是空地(F), 其他是障碍(R).找一个全部由F 组成的面积最大的子矩阵, 输出其面积乘以3的结果. 思路:如果用枚举的方法,时间复杂度是O(m^2 ...

  9. LA 4127 - The Sky is the Limit (离散化 扫描线 几何模板)

    题目链接 非原创 原创地址:http://blog.csdn.net/jingqi814/article/details/26117241 题意:输入n座山的信息(山的横坐标,高度,山底宽度),计算他 ...

随机推荐

  1. opensue "Have a lot of fun..."的出处

    每次登陆opensuse都会出现“Have a lot of fun...”,觉得奇怪. 通过搜索发现在这是/etc/motd文件中配置的. MOTD(5)                       ...

  2. cocos2dx for lua 加密图片

    图片加密的方法有很多种,在cocos2dx中,经常会使用TexturePacker来加密图片,方法如下: 打开TexturePacker,点击Add Sprite添加图片,在output栏下的Text ...

  3. DD命令做备份和恢复

    正确的备份方法是先挂载移动硬盘分区:mount /dev/sdb5 /mnt 然后再备份:dd if=/dev/sda of=/mnt/backup_sda.img 恢复时同样要先挂载,再恢复:mou ...

  4. Linux - 后台运行 ctrl + z , jobs , bg , fg

    一.& 最经常被用到 这个用在一个命令的最后,可以把这个命令放到后台执行 二.ctrl + z 可以将一个正在前台执行的命令放到后台,并且暂停三.jobs查看当前有多少在后台运行的命令四.fg ...

  5. (69)zabbix监控惠普打印机

    假设公司有多个楼层或者分布在不同楼,打印机自然分布很广泛,打印机缺少油墨或者卡纸了,都需要员工找IT部门.我们使用zabbix对打印机进行监控,一旦缺少油墨,zabbix发出报警,it人员能够及时更换 ...

  6. quartz 任务调度

    quartz 设置参数, 获取参数 在job中使用spring注入的service对象 循环获取所有的job 删除job @PersistJobDataAfterExecution @Disallow ...

  7. Thinkphp5 的常用连式查询

    目录 取出表中改字符串前两位等于01的数据 按主键查询 不按主键查 JOIN方法 的左右连接 not in 方法 like 查询 where 按条件筛选查询 取出表中改字符串前两位等于01的数据 $p ...

  8. UVa - 1593 代码对齐(STL)

    看上去十分麻烦的一道题,但是看了看别人的写法感觉大神们写的无比简单. 就是记一个每列单词的最大长度,然后剩下的事交给NB的iomanip头文件就好. stringsteam是一个神奇的东西. #inc ...

  9. debian安装中文字体

    debian刚安装完成之后,因为没有中文字体,会出现方框. 安装中文字体: $ su # apt-get install fonts-arphic-bkai00mp fonts-arphic-bsmi ...

  10. Linux学习-服务器硬件数据的收集

    以系统内建 dmidecode 解析硬件配备 系统有个名为 dmidecode 的软件,它可以解析 CPU 型号.主板型号与内存相 关的型号等等~ [root@study ~]# dmidecode ...