The famous Korean internet company has provided an internet-based photo service whichallows The famous Korean internet company users to directly take a photo of an astronomical phenomenonin space by controlling a high-performance telescope owned by . A few days later, ameteoric shower, known as the biggest one in this century, is expected. has announced a photocompetition which awards the user who takes a photo containing as many meteors as possible by usingthe photo service. For this competition, provides the information on the trajectoriesof 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 meteors, each moving in uniform linear motion; the meteor mi moves along the trajectorypi + t × vi over time t, where t is a non-negative real value, piis the starting point of mi and viisthe velocity of mi. The point pi = (xi, yi) is represented by X-coordinate xi and Y -coordinate yiinthe (X, Y )-plane, and the velocity vi = (ai, bi) is a non-zero vector with two components ai and biin the (X, Y )-plane. For example, if pi = (1, 3) and vi = (−2, 5), then the meteor mi will be at theposition (0, 5.5) at time t = 0.5 because pi + t × vi = (1, 3) + 0.5 × (−2, 5) = (0, 5.5). The telescopehas a rectangular frame with the lower-left corner (0, 0) and the upper-right corner (w, h). Refer toFigure 1. A meteor is said to be in the telescope frame if the meteor is in the interior of the frame (noton the boundary of the frame). For example, in Figure 1, p2, p3, p4, and p5 cannot be taken by thetelescope at any time because they do not pass the interior of the frame at all. You need to compute atime at which the number of meteors in the frame of the telescope is maximized, and then output themaximum number of meteors.Figure 1InputYour program is to read the input from standard input. The input consists of T test cases. Thenumber of test cases T is given in the first line of the input. Each test case starts with a line containingtwo integers w and h (1 ≤ w, h ≤ 100, 000), the width and height of the telescope frame, which areseparated by single space. The second line contains an integer n, the number of input points (meteors),1 ≤ n ≤ 100, 000. Each of the next n lines contain four integers xi, yi, ai, and bi; (xi, yi) is the startingpoint pi and (ai, bi) is the nonzero velocity vector vi of the i-th meteor; xi and yi are integer valuesbetween -200,000 and 200,000, and ai and bi are integer values between -10 and 10. Note that at leastone of ai and biis not zero. These four values are separated by single spaces. We assume that allstarting points pi are distinct.OutputYour program is to write to standard output. Print the maximum number of meteors which can be inthe telescope frame at some moment.
//这道题其实不是很难,它先需要你把一颗流星的出入时间算出来(不经过的就不记录!)然后
//在把所有的出入时间排序,用0,1标志,遇到用入时间标志时间的ans+1,不然ans-1.//ans代表的是这一个时刻有多少颗流星
#include<cstdio>
#include<algorithm>
using namespace std;
void e(double x,double a,double w,double&l,double&r){//算出这颗流星的出入时间
if(a==0){
if(x<=0||x>=w)r=l-1;
}
//有不等式组:0<a*time+x<w 得到
else if(a>0){
l=max(l,-x/a);
r=min(r,(w-x)/a);
}
else {
l=max(l,(w-x)/a);
r=min(r,-x/a);
}
}
struct wo{
int num;//0代表是入,1代表是出
double v;
};
int n,t;
double w,h;
int s;
double x,y,L,R;
double c,d;
int ans,maxn;
int cmp(wo a,wo b){
if(a.v==b.v)return a.num>b.num;//出端事件(先出后进)放前面,不然会导致答案错误
return a.v<b.v;
}
wo a[220005];
int main(){
scanf("%d",&t);
while(t--){
s=0;
scanf("%lf%lf%d",&w,&h,&n);
for(int i=1;i<=n;i++){
scanf("%lf%lf%lf%lf",&x,&y,&c,&d);
L=0,R=1e9;
e(x,c,w,L,R);
e(y,d,h,L,R);
if(R>L){//如果这可流星有一段时间在里面,那么我们就把它记录下来
a[++s].v=L,a[s].num=0;
a[++s].v=R,a[s].num=1;
}
}
ans=0,maxn=0;
sort(a+1,a+s+1,cmp);
for(int i=1;i<=s;i++){
if(a[i].num==1)ans--;
else ans++;
maxn=max(maxn,ans);
}
printf("%d\n",maxn);
}
return 0;
}