/* ***********************************************
Author :fisty
Created Time :2014/12/23 21:56:54
File Name :uva1398.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define MAX_N 100000+100
void update(int x, int a, int w, double& L, double& R){
//0 < x + at < w
if(a == 0){
if(x <= 0 || x >= w) R = L - 1; //无解
}else if(a > 0){
// -x/a < t < (w-x)/a
L = max(L, -(double)x/(double)a);
R = min(R, (double)(w-x)/(double)a);
}else{
//a < 0
L = max(L, (double)(w-x)/(double)a);
R = min(R, -(double)x/(double)a);
}
}
struct node{
double x;
int type;
//node(double _x = 0, int _type = 0):x(_x), type(_type){}
bool operator < (const node& a) const {
return x < a.x || (x == a.x && type > a.type);
}
}event[MAX_N*2];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
cin.tie(0);
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n,w, h;
int e = 0;
cin >> w >> h;
cin >> n;
//printf("w:%d h:%d n:%d\n", w, h, n);
for(int i = 0;i < n; i++){
int x, y, a, b;
cin >> x >> y >> a >> b;
//printf("%d %d %d %d\n", x,y,a,b);
double L = 0, R = 1e9;
update(x , a, w , L, R);
update(y , b, h , L, R);
//printf("L:%d R:%d\n",L,R);
if(R > L){
event[e++] = (node){L, 0};
event[e++] = (node){R, 1};
}
}
sort(event, event + e);
int cnt = 0, ans = 0;
for(int i = 0;i < e; i++){
if(event[i].type == 0){
ans = max(ans, ++cnt);
}else{
cnt--;
}
}
cout << ans << endl;
}
return 0;
}
uva1398 线性扫描
最新推荐文章于 2023-08-14 22:27:57 发布