Test instructions
Give the initial position and motion vectors of the meteor, give the camera's shooting range, ask you how many shooting stars can be shot;
Ideas:
The meteor is represented by the time period that appears in the camera's shooting range, and the maximum value is updated at the sweep end point after the sort;
AC Code:
#include <bits/stdc++.h>/*#include <vector> #include <iostream> #include <queue> #include <cmath> #include <map > #include <cstring> #include <algorithm> #include <cstdio>*/using namespacestd;#definefor (i,j,n) for (int i=j;i<=n;i++)#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong Longll;template<classT>voidRead (t&num) { CharCH;BOOLf=false; for(Ch=getchar (); ch<'0'|| Ch>'9'; f= ch=='-', ch=GetChar ()); for(num=0; ch>='0'&&ch<='9'; num=num*Ten+ch-'0', ch=GetChar ()); F&& (num=-num);}intstk[ -], Tp;template<classT> Inlinevoidprint (T p) {if(!p) {Puts ("0");return; } while(p) stk[++ TP] = p%Ten, p/=Ten; while(TP) Putchar (stk[tp--] +'0'); Putchar ('\ n');}ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);ConstLL inf=1e18;Const intn=2e5+Ten;Const intmaxn=1005;Const Doubleeps=1e-Ten;DoubleL,r;structseg{DoublePO; inttype;} seg[2*N];intcmp (Seg x,seg y) {if(X.PO==Y.PO)returnx.type<Y.type; returnx.po<Y.po;}voidOpeDoubleBDoubleSDoublev) { if(v==0) { if(b<=0|| B>=s) r=l-1; } Else if(v>0) {L=max (l,-b/v); R=min (R, (s-b)/v); } Else{L=max (L, (s-b)/v); R=min (r,-b/v); }}intMain () {intT; Read (t); while(t--) { intN; Doublew,h; scanf ("%LF%LF",&w,&h); Read (n); intCnt=0; For (I,1, N) {L=0, r=1000000000; Doublex,y,a,b; scanf ("%LF%LF%LF%LF",&x,&y,&a,&b); Ope (X,w,a); Ope (Y,H,B); if(r<=l)Continue; seg[++cnt].po=l; Seg[cnt].type=1; seg[++cnt].po=R; Seg[cnt].type=0; } Sort (Seg+1, seg+cnt+1, CMP); intans=0, num=0; For (I,1, CNT) { if(Seg[i].type) num++; Elsenum--; Ans=Max (ans,num); } cout<<ans<<"\ n"; } return 0;}
LA-3905 (scan line)