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 meteormi moves along the trajectory pi + t×vi over 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 = (xi,yi) is represented by X-coordinatexi and Y-coordinateyi in the (X,Y)-plane, and the velocity vi = (ai,bi) is a non-zero vector with two components ai and bi in the(X, Y)-plane. For example, if pi = (1, 3) and vi = (-2, 5), then the meteormi will be at the position (0, 5.5) at timet = 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(w, h). 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,p2, p3, p4, andp5 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.
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 integersw and h (1w,h100, 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),1n100, 000. Each of the next n lines contain four integersxi, yi, ai, andbi; (xi,yi) is the starting point pi and(ai, bi) is the nonzero velocity vectorvi of the i-th meteor;xi and yi are integer values between -200,000 and 200,000, andai and bi are integer values between -10 and 10. Note that at least one ofai and bi is not zero. These four values are separated by single spaces. We assume that all starting pointspi 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
刘汝佳大白书上的扫描法
将有效的流星进入摄像头和离开摄像头的时间处理为一个区间,然后把区间左右端点处理成两个事件,遇到左事件答案加1,遇到右事件答案减一,取最大就是最后的答案,我是一个渣渣,所以代码跟刘汝佳的差不多,弱爆了!!!!!!!
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<utility>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define Inf (1<<30)
#define LL long long
#define MOD 1000000009
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int MM = 100005;
struct node
{
double x;
int type;
bool operator <(const node &other)const{
if (x==other.x)return type < other.type;//右端点是0,左端点是1
return x < other.x;
}
}A[MM*2];
void update(int x, int v, int w, int &L, int &R)
{
if (v == 0)
{
if (x <= 0 || x >= w)R = L - 1;
}
else if (v>0)
{
L = max(L, -x * 2520 / v);
R = min(R, (w - x) * 2520 / v);
}
else
{
L = max(L, (w - x) * 2520 / v);
R = min(R, -x * 2520 / v);
}
}
int main() {
int T, n, w, h;
//freopen("D:\\oo.txt","r",stdin);
scanf("%d", &T);
while (T--)
{
int cnt = 0;
scanf("%d%d%d", &w, &h, &n);
for (int i = 0; i < n; i++)
{
int x, y, a, b;
scanf("%d%d%d%d", &x, &y, &a, &b);
int L = 0, R = 1e9;
update(x, a, w, L, R);
update(y, b, h, L, R);
if (R>L)
{
A[cnt++] = node{ L, 1 };
A[cnt++] = node{ R, 0 };
}
}
sort(A, A + cnt);
int num = 0, ans = 0;
for (int i = 0; i < cnt; i++)
{
if (A[i].type == 1)num++;
else num--;
ans = max(num, ans);
}
printf("%d\n", ans);
}
return 0;
}