Hdu2389 Rain on your Parade (HK binary chart max match)

Source: Internet
Author: User

Rain on your Parade
Problem Description you ' 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.

Input the 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 <= s I <=) 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.

Output for 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

2 1 2 1 0 3 3 0 3 2 4 0 6 0 1 2 1 1 2 3 3 2 2 2 2 4 4
Sample Output
Scenario #1:2 Scenario #2:2
Source HDU 2008-10 Public Contest
Recommend LCY
——————————————————————————————————

The title means give the person's position and speed, m the position of the umbrella, ask how many people in t seconds to get the umbrella

Idea: The two-figure match with the umbrella, data large Hungarian-fried, with Hopcroft-karp method

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath > #include <algorithm> #include <queue> #include <vector> #include <set> #include <stack&
Gt

#include <map> #include <climits> using namespace std;

const int MAXN = 3010;//Left node number, right node number const int MAXM = 3010*3010;//edge number const int INF = 0x7FFFFFFF;
    struct Edge {int v;
int next;

} EDGE[MAXM];
int NX, NY;
int cnt;

int dis;
int FIRST[MAXN];
int XLINK[MAXN], YLINK[MAXN]; /*xlink[i] Represents the right collection vertex ordinal of the left collection vertex, Ylink[i] represents the left collection vertex number to which the right collection I vertex matches.
*/int DX[MAXN], DY[MAXN]; /*dx[i] represents the distance number of the left collection I vertex, dy[i] represents the distance number of the right set i vertex */int VIS[MAXN];


Search for an augmented path tag array struct point {int x,y,v;} A[MAXN],B[MAXN];
    void init () {cnt = 0;
    memset (First,-1, sizeof (first));
    memset (XLink,-1, sizeof (xlink));
memset (Ylink,-1, sizeof (Ylink));
    } void Read_graph (int u, int v) {edge[cnt].v = v;
Edge[cnt].next = First[u], first[u] = cnt++; } intBFS () {queue<int> q;
    dis = INF;
    memset (DX,-1, sizeof (DX));
    memset (Dy,-1, sizeof (DY));
            for (int i = 0; i < NX; i++) {if (xlink[i] = = 1) {Q.push (i);
        Dx[i] = 0;
        }} while (!q.empty ()) {int u = q.front ();
        Q.pop ();
        if (Dx[u] > dis) break;
            for (int e = First[u]; E! =-1; e = edge[e].next) {int v = EDGE[E].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 e = First[u]; E! =-1; e = edge[e].next) {int v = EDGE[E].V;
            if (!vis[v] && dy[v] = = dx[u]+1) {Vis[v] = 1; if (ylink[v]! =-1 &&
            DY[V] = = dis) continue;
                if (ylink[v] = = 1 | | find (YLINK[V])) {Xlink[u] = V, ylink[v] = u;
            return 1;
}}} return 0;
    } int Maxmatch () {int ans = 0;
        while (BFS ()) {memset (Vis, 0, sizeof (VIS));
            for (int i = 0; i < NX; i++) if (xlink[i] = = 1) {ans = = find (i);
}} return ans;
    } int main () {int t,t;
    int q=1;
    scanf ("%d", &t);
        while (t--) {init ();
        scanf ("%d", &t);
        scanf ("%d", &nx);
        for (int i=0; i<nx; i++) {scanf ("%d%d%d", &AMP;A[I].X,&AMP;A[I].Y,&AMP;A[I].V);
        } scanf ("%d", &ny);
        for (int i=0; i<ny; i++) {scanf ("%d%d", &b[i].x,&b[i].y); } for (int i=0, i<nx; i++) for (int j=0; j<ny; J + +) {if ((A[i].x-b[j]. X) * (a[i].x-b[j].x) + (A[i].Y-B[J].Y) * (A[I].Y-B[J].Y) <=t*a[i].v*t*a[i].v) read_graph (I,J);

        } int ans = Maxmatch ();
    printf ("Scenario #%d:\n%d\n\n", Q++,ans);
} return 0; }






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.