HDU 2389 Rain on your Parade (binary chart HK algorithm)

Source: Internet
Author: User

#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", &AMP;P[I].X,&AMP;P[I].Y,&AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.