蓝书中的扫描线裸题。
顺便作为计算几何练手。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<stack>
#define INF 2100000000
#define ll long long
#define clr(x) memset(x,0,sizeof(x))
using namespace std;
const int maxn = 1e5+20;
void updata(int x,int a,int w,double &L,double &R){
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);
}
}
}
struct Event{
double x;
int type;
bool operator < (const Event &rhs)const{
return x<rhs.x||(x==rhs.x&&type>rhs.type);
}
};
Event events[maxn<<1];
int Ti,Wild_,high_,num,ech,xi_,ai_,yi_,bi_,ans,cnt;
int main(){
scanf("%d",&Ti);
while(Ti--){
scanf("%d%d%d",&Wild_,&high_,&num),ech=0,ans=0,cnt=0;
for(int i=0;i<num;i++){
scanf("%d%d%d%d",&xi_,&yi_,&ai_,&bi_);
double L=0,R=1e9;
updata(xi_,ai_,Wild_,L,R);
updata(yi_,bi_,high_,L,R);
if(R>L){
events[ech++]=(Event){L,0};
events[ech++]=(Event){R,1};
}
}
sort(events,events+ech);
for(int i=0;i<ech;i++){
if(events[i].type==0)ans=max(ans,++cnt);
else --cnt;
}
cout<<ans<<endl;
}
return 0;
}
话说我也是从这道题上面学习的struct的各种在当时看来灵活的用法。1年多了,再看这道提,感觉自己的进步还是很少呀。必须得努力了,现在放水已经考不过同班的同学了。