问题
https://vj.z180.cn/02243501f2d6b293cf3449525510293e?v=1583390881
分析
将问题转化为区间的覆盖问题,一个点对应的最多有多少个区间。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn=100000+5;
struct Point{
double pos;
int type;
bool operator < (const Point &rhs) const {
//先处理数值小的,数值相同先处理右端点
return pos<rhs.pos || (pos==rhs.pos && type>rhs.type);
}
}point[2*maxn];
void update(int x,int a,int w,double &L,double &R){
if(x<=0) {
if(a<=0) R=L;
else{
L=max(L,(double)(-x)/a);
R=min(R,(double)(w-x)/a);
}
}else if(x>=w){
if(a>=0) R=L;
else{
L=max(L,(double)(x-w)/-a);
R=min(R,(double)x/-a);
}
}else {
if(a>0) R=min(R,(double)(w-x)/a);
else if(a<0) R=min(R,(double)x/-a);
}
}
int n,kase=0,w,h,x,y,a,b;
double L,R;
int main(void){
scanf("%d",&kase);
while(kase--){
int cnt=0;
scanf("%d%d%d",&w,&h,&n);
for(int i=0;i<n;++i){
scanf("%d%d%d%d",&x,&y,&a,&b);
L=0,R=1e9;
update(x,a,w,L,R);
update(y,b,h,L,R);
if(L>=R) continue; //这一步很重要,不加的话会记录干扰的时间
point[cnt++]=(Point){L,-1};
point[cnt++]=(Point){R,1};
}
sort(point,point+cnt);
int ans=0,cur=0;
for(int i=0;i<cnt;++i){
if(point[i].type==-1){
++cur;
ans=max(ans,cur);
}else --cur;
}
printf("%d\n",ans);
}
return 0;
}