Menteor

来源:互联网 发布:大数据主要做什么 编辑:程序博客网 时间:2024/06/06 04:04

Description

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 meteors, each moving in uniform linear motion; the meteor mi moves along the trajectory pi + t×viover time t , where t is a non-negative real value, pi is the starting point of mi and vi is the velocity ofmi . The point pi = (xiyi) is represented by X -coordinate xi and Y -coordinate yi in the (XY) -plane, and the velocity vi = (aibi) is a non-zero vector with two components ai and bi in the (XY) -plane. For example, if pi = (1, 3) and vi = (-2, 5) , then the meteor mi will be at the position (0, 5.5) at time t = 0.5 because pi + t×vi = (1, 3) + 0.5×(-2, 5) = (0, 5.5) . The telescope has a rectangular frame with the lower-left corner (0, 0) and the upper-right corner (wh) . 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 , and p5 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.

\epsfbox{p3905.eps}

Input

Your program is to read the input from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing two integers wand h (1$ \le$wh$ \le$100, 000) , the width and height of the telescope frame, which are separated by single space. The second line contains an integer n , the number of input points (meteors), 1$ \le$n$ \le$100, 000 . Each of the next n lines contain four integers xiyiai , and bi ; (xiyi) is the starting point pi and (aibi) is the nonzero velocity vector vi of the i -th meteor; xi and yi are integer values between -200,000 and 200,000, and ai and bi are integer values between -10 and 10. Note that at least one of ai and bi is not zero. These four values are separated by single spaces. We assume that all starting points pi 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
显然,要看能不能找到流星,我们只需要求出流行出现在镜头里的时间段就可以了,因为在边界上的流星是看不到的,所以是开区间。如何来求能看到最多流星的时刻呢?我们在这里应用“扫描法”。把所有区间按照开始时间的早晚排列,用一条线从左到右扫描区间,这条线与区间交点最多的位置就是我们要求的的时刻。我们把所有的端点都存储起来,遇到左端点加一(说明此时线与一个区间有交点),遇到右端点减一(一个区间结束,与它不会再有交点)。但是如果一个区间的右端点和另一个区间的左端点重合,此时最多就只能照到一个流星,所以这时我们把重合的右端点排在前面。这道题还用到了函数重载,函数重载就是对运算符赋予新的定义,格式为operator运算符(参数){函数体}。代码如下:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int maxm=200000+3;struct events{double x;int type;bool operator<(const events &a)const{return x<a.x||(x==a.x&&type>a.type);}}d[maxm];void upload(int x,int a,int w,double &L,double &R) //这里是对L,R的地址进行运算,才能更改其值{if(a==0){if(x<=0||x>=w) R=L-1;}else if(a>0){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);}}int main(){int T;cin>>T;while(T--){int w,h,n,e=0;cin>>w>>h>>n;for(int i=0;i<n;i++){int x,y,a,b;scanf("%d%d%d%d",&x,&y,&a,&b);double L=0,R=2000000;upload(x,a,w,L,R);upload(y,b,h,L,R);if(L<R){d[e++]=(events){L,0};d[e++]=(events){R,1};}}sort(d,d+e);int ans=0,cnt=0;for(int i=0;i<e;i++){if(d[i].type==0) ans=max(ans,++cnt);else --cnt;}cout<<ans<<endl;}return 0;}

0 0
原创粉丝点击