Rain on your ParadeTime
limit:3000MS
Memory Limit:165535KB
64bit IO Format:%i64d &%i6 4u SubmitStatusPracticeHDU 2389
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
2121 0 33 0 324 06 0121 1 23 3 222 24 4
Sample Output
Scenario #1:2Scenario #2:2 The main problem: T group test Data. Each group to t means that there is still t minutes to rain, and then to N, indicating that there are n tourists, respectively, given the x,y,s represents the two-dimensional coordinates and movement speed. Then M said there is M shelter, give X, Y to represent two-dimensional coordinates, each visitor is unwilling to share the shelter with other people, ask T minutes, up to how many visitors can shelter from the rain. Problem-Solving ideas: the maximum match. Visitors and shelters are divided into two parts. If a visitor can move farther than the current distance from a shelter, it means he can pass the rain. Even one side. Enumerate for all visitors. The map is completed. However, this topic is not difficult to build, but a large amount of data, two of the figures on both sides of the vertices are 3,000. Then it may be up to 9*10^6, and if you use the complexity of Hungary's v*e, it will definitely time out. So here we use Hopcroft-karp to find the maximum match.
#include <stdio.h> #include <string.h> #include <math.h> #include <queue> #include <vector > #include <algorithm>using namespace std;const int maxn = 3100;const int INF = 0x3f3f3f3f;const double eps = 1e-5; struct guest{double x,y,s;} Guests[maxn];struct umbrella{double x, y;} UMBRELLAS[MAXN];d ouble Distan (guest A,umbrella b) {double dx = a.x-b.x; Double dy = a.y-b.y; return sqrt (dx*dx+dy*dy);} Vector<int>g[maxn];int MX[MAXN], MY[MAXN], DX[MAXN], DY[MAXN], USED[MAXN], dis;bool searchp (int _n) {//Parameters x number of vertices, Processing out dx and dy array queue<int>q; memset (dx,-1,sizeof (DX)); memset (dy,-1,sizeof (dy)); int dis = INF; for (int i = 1; I <= _n; i++) {if (mx[i] = = 1) {//The non-covered point of X is enqueued dx[i] = 0; Q.push (i); }} int v; while (! Q.empty ()) {int u = q.front (); Q.pop (); if (Dx[u] > dis) break; No smaller dis for (int i = 0; i < g[u].size (); i++) {v = g[u][i]; IfDY[V] = = 1) {//if V at Y has not visited dy[v] = Dx[u] + 1; Update dy if (my[v] = = 1) {//if V on Y is an open point, find the shortest augmented path length dis = dy[v]; }else{Dx[my[v]] = Dy[v] + 1; Update v X-match point Q.push (My[v]); Queue V's match point}}}} return dis! = INF; Found the shortest augmented path}int dfs (int u) {int V; for (int i = 0; i < g[u].size (); i++) {v = g[u][i]; if (!used[v] && dy[v] = = Dx[u] + 1) {//v is not visited and the distance is 1 used[v] = 1; if (my[v]! =-1 && dy[v] = = dis) {//if V is not an open point and is already equal to the shortest extended distance from the origin point, it indicates that there is a shorter way to augment the continue; } if (my[v] = = 1 | | DFS (MY[V])) {//if V is a Y-not-covered point or the X-node that originally matched V can find another match mx[u] = v; Match U, v my[v] = u; return true; }}} return false;} int maxmatch (int ln,int rn) {//the number of left and right vertices of the pass parameter, returns the maximum number of matches int ret = 0; memset (mx,-1,sizeof (Mx)); X initializes the memset (my,-1,sizeof (My)); Y initializes the not-covered point while (SEARCHP (LN)) {memset (used,0,sizeof (used)); Initialization is not accessed for (int i = 1; i <= ln; i++) {if (mx[i] = = 1 && dfs (i)) {//If x is not covered and the augmented path is found ret++; }}} return ret;} int main () {int T, cas = 0, n, m; Double T; scanf ("%d", &t); while (t--) {scanf ("%lf", &t); scanf ("%d", &m); for (int i = 0; I <= m; i++) {g[i].clear (); } for (int i = 1; I <= m; i++) {scanf ("%lf%lf%lf", &GUESTS[I].X,&GUESTS[I].Y,&GUESTS[I].S); } scanf ("%d", &n); for (int i = 1; I <= n; i++) {scanf ("%lf%lf", &umbrellas[i].x,&umbrellas[i].y); } for (int i = 1, i <= m; i++) {for (int j = 1; J <= N; j + +) {double dd = Distan (gues TS[I],UMBRELLAS[J]); if (GUESTS[I].S * t >= DD) {G[i].push_back (j); }}} int res = Maxmatch (m,n); printf ("Scenario #%d:\n%d\n\n", ++cas,res); } return 0;}
HDU 2389--rain on your Parade —————— "Hopcroft-karp for maximum match, sqrt (n) *e complexity"