#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath >using namespace Std;const int inf=0x3f3f3f3f;const int maxn=3003;const int Maxm=maxn*maxn;int xlink[maxn],ylink[ Maxn];int dx[maxn],dy[maxn];int head[maxn];int dis;bool vis[maxn];int n,m,t;int ecnt;struct Edge{int v,next; Edge () {} edge (int v,int next): V (v), next (next) {}}e[maxm];struct node{double x,y,v;} P[MAXN],U[MAXN];d ouble getdis (node A,node b) {double dx=a.x-b.x; Double dy=a.y-b.y; return sqrt (dx*dx+dy*dy);} void Add (int u,int v) {E[ecnt]=edge (v,head[u]); head[u]=ecnt++;} BOOL BFs () {memset (dx,-1,sizeof dx); memset (dy,-1,sizeof dy); queue<int>q; for (int i=0;i<n;i++) {if (xlink[i]==-1) {dx[i]=0; Q.push (i); }} Dis=inf; while (!q.empty ()) {int U=q.front (); Q.pop (); if (Dx[u]>dis) break; for (int i=head[u];i!=-1;i=e[i].next) {int v=e[i].v; If(Dy[v]==-1) {dy[v]=dx[u]+1; if (ylink[v]==-1) dis=dy[v]; else{dx[ylink[v]]=dy[v]+1; Q.push (Ylink[v]); }}}} return dis!=inf;} int find (int u) {for (int i=head[u];i!=-1;i=e[i].next) {int v=e[i].v; if (Vis[v]) continue; if (dy[v]==dx[u]+1) {vis[v]=1; if (Ylink[v]!=-1&&dy[v]==dis) continue; if (ylink[v]==-1| | Find (Ylink[v])) {ylink[v]=u; Xlink[u]=v; return 1; }}} return 0;} int HK () {int ans=0; while (BFS ()) {memset (vis,0,sizeof vis); for (int i=0;i<n;i++) if (xlink[i]==-1) {ans+=find (i); }} return ans; void Solve () {scanf ("%d%d", &t,&n); for (int i=0;i<n;i++) scanf ("%lf%lf%lf", &P[I].X,&P[I].Y,&P[I].V); scanf ("%d", &m); for (int i=0;i<m;i++) scanf ("%lf%lf", &u[i]. x,&u[i].y); memset (head,-1,sizeof head); memset (xlink,-1,sizeof xlink); memset (ylink,-1,sizeof ylink); ecnt=0; for (int i=0;i<n;i++) for (int j=0;j<m;j++) {double Dis=getdis (p[i],u[j]); Double d=p[i].v*t; if (D>=dis) Add (I,J); } printf ("%d\n\n", HK ());} int main () {//Freopen ("in", "R", stdin); int T,cas=1; cin>>t; while (t--) {printf ("Scenario #%d:\n", cas++); Solve (); } return 0;}
HDU 2389 Rain on your Parade (binary chart HK algorithm)