思路:
得出每个流星出现在长方形内部的进入、退出时间并存起来。
按时间从小到大,遇到进入时间就+1,遇到退出时间就-1。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vll;
const int MAXN = 1e6 + 10;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const double eps = 1e-8;
int n, m, k;
typedef struct Node{
double val;
int type, id;
Node(double a, int b, int c){
val = a;
type = b;
id = c;
}
bool operator < (const Node &rhs) const{
if(fabs(val - rhs.val) < eps)
return type < rhs.type;
return val - rhs.val > -eps;
}
}Node;
int w, h;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int times;
cin >> times;
while(times--){
priority_queue<Node> q;
cin >> w >> h >> n;
for(int i = 0; i < n; i++){
int x, y, a, b;
cin >> x >> y >> a >> b;
if((x < 0 && a <= 0) || (x > w && a >= 0) || (y < 0 && b <= 0) || (y > h && b >= 0) || (x == 0 && a == 0) || (x == w && a == 0) || (y == 0 && b == 0) || (y == h && b == 0))
continue;
double x1 = x > 0 && x < w ? 0 : (double)min(abs(x), abs(x - w)) / abs(a);
double x2 = a ? max((double)-x / a, (double)(w - x) / a) : INF;
double y1 = y > 0 && y < h ? 0 : (double)min(abs(y), abs(y - h)) / abs(b);
double y2 = b ? max((double)-y / b, (double)(h - y) / b) : INF;
double u = max(x1, y1);
double v = min(x2, y2);
// cerr << i << " " << u << " " << v << endl;
if(u - v > -eps)
continue;
q.push(Node(u, 0, i + 1));
q.push(Node(v, 1, i + 1));
}
int res, cur;
res = cur = 0;
while(!q.empty()){
cur += q.top().type * (-2) + 1;
res = max(res, cur);
q.pop();
}
cout << res << endl;
}
cerr << "execute time : " << (double)clock() / CLOCKS_PER_SEC << endl;
return 0;
}
未来可期。