HDU 2389 Rain on your Parade (binary graph matching (hopcroft-carp algorithm template))

Source: Internet
Author: User

Rain on your ParadeTime limit:6000/3000 MS (java/others) Memory limit:655350/165535 K (java/others)
Total submission (s): 3033 Accepted Submission (s): 952


Problem Descriptionyou ' re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone are here. It's a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imagined. It could is the perfect end of a beautiful day.
But nothing ever is perfect. One of your guests works in weather forecasting. He suddenly yells, "I know that breeze! It means It going to rain heavily in just a few minutes! " Your guests all wear their best dresses and really would does like to get wet, hence they stand terrified when hearing the Bad news.
You have prepared a few umbrellas which can protect a few of your guests. The umbrellas is small, and since your guests is all slightly snobbish, no guest would share an umbrella with other guest S. The umbrellas is spread across your (gigantic) garden and just like your guests. To complicate matters even more, some of your guests can ' t run as fast as the others.
Can your guests so as many as possible find a umbrella before it starts to pour?

Given the positions and speeds of all your guests, the positions of the umbrellas, and the time until it starts to rain, F IND out what many of your guests can at the most reach an umbrella. The want to share a umbrella, however. Guests do not.

Inputthe input starts with a line containing a single integer, the number of the test cases.
Each test case starts with a line containing the time t in minutes until it would start to rain (1 <=t <= 5). The next line contains the number of guests m (1 <= m <= in), followed by M lines containing X-and y-coordinates As well as the speed Si in units per minute (1 <= si <=) of the A guest as integers, separated by spaces. After the guests, a single line contains n (1 <= n <=), the number of umbrellas, followed by n lines containing The integer coordinates of each umbrella, separated by a space.
The absolute value of all coordinates was less than 10000.

Outputfor Each test case, write a line containing "Scenario #i:", where I am the number of the the test case starting at 1. Then, write a single line that contains the number of guests that can at the very reach an umbrella before it starts to rain. Terminate every test case with a blank line.

Sample Input
2121 0 33 0 324 06 0121 1 23 3 222 24 4

Sample Output
Scenario #1:2Scenario #2:2

Sourcehdu 2008-10 Public ContestTest Instructions: The first row of cases, the first row of each case represents how many units of time it began to rain, then n visitors, the next n rows is the location of each visitor (within the one-dimensional coordinate plane) and his movement speed, then the M-line represents the number of umbrellas, then M-line represents the position of each umbrella, asked before the rain The maximum number of people can get an umbrella (two people cannot share an umbrella).
Resolution: In a given time the wife can reach the position of the umbrella to build the side, the two largest match, if directly with the classical Hungarian algorithm must be a certain time-out, available Hopcroft-karp algorithm (O (sqrt (n) *edgnum). 546MS AC.
#include <stdio.h> #include <string.h> #include <queue> #include <math.h>using namespace std;  const int N = 3005;const int Inf=1<<28;int head[n],to[n*n],next1[n*n],tot;                 Save diagram int Dx[n],dy[n],dis;            The left part distance, the right part distance, record the maximum distance of the point not matched by the right part int machx[n],nx,machy[n]; The left part points match the right point, the number of points on the left, the right part matches the left point bool vist[n];void addedg (int u,int v) {to[tot]=v; next1[tot]=head[u]; head[u]=tot++;}    BOOL SearchPath () {//Find out if there is no augmented road queue<int>q;    Dis=inf;    memset (dx,-1,sizeof (DX));    memset (dy,-1,sizeof (dy));    for (int i=1; i<=nx; i++) if (machx[i]==-1) Q.push (i), dx[i]=0;        while (!q.empty ()) {int U=q.front (); Q.pop ();        if (Dx[u]>dis) break;            for (int i=head[u]; i!=-1; i=next1[i]) {int v=to[i];                if (dy[v]==-1) {dy[v]=dx[u]+1;                if (machy[v]==-1) dis=dy[v];                    else{dx[machy[v]]=dy[v]+1; Q.push (MACHY[V]); }}}} return dis!=inf;}        BOOL Findroad (int u) {for (int i=head[u]; i!=-1; i=next1[i]) {int v=to[i];            if (!vist[v]&&dy[v]==dx[u]+1) {vist[v]=1;            if (Machy[v]!=-1&&dy[v]==dis) continue; if (machy[v]==-1| |  Findroad (Machy[v]) {machy[v]=u; machx[u]=v;            return true; }}} return false;}    int Maxmatch () {int ans=0;    memset (machx,-1,sizeof (MACHX));    memset (machy,-1,sizeof (machy));        while (SearchPath ()) {memset (vist,0,sizeof (vist));    for (int i=1; i<=nx; i++) if (machx[i]==-1) ans+=findroad (i); } return ans;    -------------The above section of the code for the template---------------------struct node{int x, y; double Dis;} Man[n],umb[n];d ouble countdis (int u,int v) {return sqrt ((man[u].x-umb[v].x) * (man[u].x-umb[v].x) *1.0+ (man[u].y-umb[v ].Y) * (MAN[U].Y-UMB[V].Y) *1.0);}    int main () {int t,ny,tim,c=0; scanf ("%d", &t);        while (t--) {scanf ("%d%d", &AMP;TIM,&AMP;NX);            for (int i=1;i<=nx;i++) {scanf ("%d%d%lf", &man[i].x,&man[i].y,&man[i].dis);        Man[i].dis*=tim;        } scanf ("%d", &ny); for (int i=1;i<=ny;i++) scanf ("%d%d", &umb[i].x,&umb[i].y);//---------------------Build------------------        ---tot=0;        memset (head,-1,sizeof (head));                for (int u=1;u<=nx;u++) for (int v=1;v<=ny;v++) if (Man[u].dis>=countdis (u,v))        ADDEDG (u,v);//----------------------------------------------int ans=maxmatch ();    printf ("Scenario #%d:\n%d\n\n", ++c,ans); } return 0;}


HDU 2389 Rain on your Parade (binary graph matching (hopcroft-carp algorithm 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.