当前位置: 代码迷 >> 综合 >> LA 3905 Meteor 扫描线 -
  详细解决方案

LA 3905 Meteor 扫描线 -

热度:40   发布时间:2023-09-23 05:37:00.0

题目地址:http://vjudge.net/problem/UVALive-3905

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(b);++i)
#define REPD(i,a,b) for(int i=a;i>=(b);--i)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
const int maxn=100000+5;
struct Event
{double x; bool Right; bool operator < (const Event& e) const {return x<e.x || (x==e.x&&Right);}
}events[maxn*2];
void update(int x,int a,int w,double& L,double& R){  //(x+a*t,y+b*t)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 argc, char const *argv[])
{int T,w,h,n; scanf("%d",&T);while(T--){scanf("%d%d%d",&w,&h,&n);int p=0;REP(i,1,n) {int x,y,a,b;scanf("%d%d%d%d",&x,&y,&a,&b);double L=0,R=1e9;update(x,a,w,L,R);update(y,b,h,L,R);if(L<R) {events[p++]=Event{L,false};events[p++]=Event{R,true};}}	 sort(events,events+p);int ans=0,cnt=0;REP(i,0,p-1){if(events[i].Right) cnt--;else cnt++;ans=max(ans,cnt);}printf("%d\n", ans);}return 0;
}