很麻煩的一個題,有不少的技巧能夠學到node
#include <set> #include <cstdio> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 100005; const int INF = 0x3fffffff; const int k = 2520;//lcm(1,2,..,10); int w,h; struct node { int pos; int dir; friend bool operator <(node a,node b) { if(a.pos==b.pos)return a.dir>b.dir; return a.pos<b.pos; } }e[maxn*2]; void solve(int x,int a,int w,int &l,int &r) { if(a==0){ if(x<=0 || x>=w)r = l-1; } else if(a>0){ l = max(l,-x/a); r = min(r,(w-x)/a); } else { l = max(l,(w-x)/a); r = min(r,-x/a); } } int main() { // freopen("in.txt","r",stdin); int T;scanf("%d",&T); while(T--) { int n;scanf("%d%d%d",&w,&h,&n); w*=k;h*=k; int cnt = 0; for(int i = 1;i<=n;++i) { int x,y,a,b; scanf("%d%d%d%d",&x,&y,&a,&b); int l = 0,r = INF; solve(x*k,a,w,l,r); solve(y*k,b,h,l,r); if(r<=l)continue; e[cnt++] = (node){l,0}; e[cnt++] = (node){r,1}; } sort(e,e+cnt); int ans = 0,t = 0; for(int i = 0;i<cnt;++i) { if(e[i].dir)t--; else t++; ans = max(ans,t); } printf("%d\n",ans); } return 0; }