HDU2389 Rain on your Parade (HK template)

Source: Internet
Author: User
Tags cas

Test instructions

In a two-dimensional coordinate system there are N-Men and M-umbrellas, each with their own moving speed,

Ask how many people can move to different umbrellas within S min (two people are not allowed to share an umbrella).

Ideas:

Because NM is too large (3000), Hungary will time out, using the HK algorithm

Organized the template of HK

/************************************************//author:d evil//created TIME:2016/5/10 23:13:51//*********** ************************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn=3010;Const intinf=0x3f3f3f3f; Vector<int>Eg[n];intAx[n],ay[n], as[N],bx[n],by[n],n,m;intMx[n],my[n];intDx[n],dy[n],dis;BOOLVis[n];BOOLBFs () {Queue<int>Q; Dis=inf; memset (DX,-1,sizeof(DX)); memset (DY,-1,sizeof(DY));  for(intI=0; i<n;i++)        if(mx[i]==-1) {Q.push (i); Dx[i]=0; }     while(!Q.empty ()) {        intu=Q.front ();        Q.pop (); if(Dx[u]>dis) Break;  for(intI=0; I<eg[u].size (); i++)        {            intv=Eg[u][i]; if(dy[v]==-1) {Dy[v]=dx[u]+1; if(my[v]==-1) dis=Dy[v]; Else{Dx[my[v]]=dy[v]+1;                Q.push (My[v]); }            }        }    }    returndis!=inf;}BOOLDfsintu) {     for(intI=0; I<eg[u].size (); i++)    {        intv=Eg[u][i]; if(!vis[v]&&dy[v]==dx[u]+1) {Vis[v]=1; if(my[v]!=-1&&dy[v]==dis)Continue; if(my[v]==-1||DFS (My[v])) {My[v]=T; Mx[u]=v; return 1; }        }    }    return 0;}intMaxmatch () {intans=0; memset (MX,-1,sizeof(MX)); Memset (My,-1,sizeof(my));  while(BFS ()) {memset (Vis,0,sizeof(VIS));  for(intI=0; i<n;i++)            if(mx[i]==-1&&DFS (i)) ans++; }    returnans;}intMain () {//freopen ("In.txt", "R", stdin);    intt,s,cas=0; scanf ("%d",&t);  while(t--)    {         for(intI=0; i<= the; i++) eg[i].clear (); scanf ("%d%d",&s,&N);  for(intI=0; i<n;i++) scanf ("%d%d%d",&ax[i],&ay[i],& as[i]); scanf ("%d",&m);  for(intI=0; i<m;i++) scanf ("%d%d",&bx[i],&By[i]);  for(intI=0; i<n;i++)             for(intj=0; j<m;j++)                if((Ax[i]-bx[j]) * (Ax[i]-bx[j]) + (Ay[i]-by[j]) * (Ay[i]-by[j]) <= as[i]* as[i]*s*s) eg[i].push_back (j); printf ("Scenario #%d:\n",++CAs); printf ("%d\n\n", Maxmatch ()); }    return 0;}

HDU2389 Rain on your Parade (HK template)

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.