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 ;
}

最新文章

  1. 利用AOP写2PC框架(一)
  2. 从接口、抽象类到工厂模式再到JVM来总结一些问题
  3. (转载)SQL— CONCAT(字符串连接函数)
  4. html图片预览
  5. 一致性算法Paxos详解
  6. Hibernate一对一关系映射
  7. Yocto开发笔记之《驱动调试-华为3G模块》(QQ交流群:519230208)
  8. [GDAL]GEOS和Proj4编译
  9. Magento中,调用静态块的几种方法
  10. JAVA面试题:equals()方法和== 区别
  11. Linux配置系统
  12. [基础] C++与JAVA的内存管理
  13. javascript sort排序
  14. linux模拟实现主机跨路由通信
  15. C#下的两种加密方式MD5和DEC
  16. git 仓库中删除历史大文件
  17. 05-树8 File Transfer (25 分)
  18. 【Codeforces 204E】Little Elephant and Strings
  19. UVA 10480 Sabotage (网络流,最大流,最小割)
  20. 2018/03/07 每日一个Linux命令 之 cat

热门文章

  1. vue axios 请求 https 的特殊处理
  2. 如何将oracle查询的结果传输给变量
  3. Boo who-freecodecamp算法题目
  4. DNS 工作原理是什么,域名劫持、域名欺骗、域名污染又是什么
  5. strace用法
  6. Lecture 2
  7. Fiddler证书安装不成功
  8. MVC&amp;JQuery如何根据List动态生成表格
  9. 使用fio测试磁盘I/O性能
  10. Django two