Gopher II
Time limit:2000 ms |
|
Memory limit:65536 K |
Total submissions:6675 |
|
Accepted:2732 |
Description
The gopher family, having averted the canine threat, must face a new predator.
The are n gophers and M gopher holes, each at distinct (x, y) coordinates. A hawk arrives and if a gopher does not reach a hole in S seconds it is vulnerable to being eaten. A hole can save at most one gopher. all the gophers run at the same velocity v. the gopher family needs an escape strategy that minimizes the number of vulnerable gophers.
Input
The input contains several cases. the first line of each case contains four positive integers less than 100: n, m, S, and V. the next n lines give the coordinates of the gophers; the following M lines give the coordinates of the gopher holes. all distances are in metres; all times are in seconds; all velocities are in metres per second.
Output
Output consists of a single line for each case, giving the number of vulnerable gophers.
Sample Input
2 2 5 101.0 1.02.0 2.0100.0 100.020.0 20.0
Sample output
1
Algorithm Analysis: At the beginning, it was very brainless, and the algorithm was a greedy strategy. Although I do not know whether it is feasible,
But my greedy strategy is like this: let every hamster drill into the farthest hole it can reach, that is to say,
Let every hamster run as far as possible before drilling holes. I found it very troublesome to implement the Code! To record each
The distance from the hamster to other holes must be sorted! It is very troublesome and I do not know whether the final result is correct.
Later I thought about the "maximum matching algorithm for bipartite graphs" that I just learned. The idea of this algorithm is: calculate the coordinates of each input hamster and the "distance" from each other"
Check whether it is within the reachable range. If it is reachable, it indicates that "the hamster" has a relationship with "the hole" and the corresponding map [] [] is marked as 1. The remaining DFS.
Figure template issues ).
# Include <math. h> # include <stdio. h> # include <string. h> int n, m; double S, V; struct N // records the coordinates of the hamster {Double X; Double Y;} Q [200]; struct node // record the coordinates of the rat hole {Double X; Double Y;} W [200]; int map [150] [150]; int VT [150]; int link [150]; int DFS (INT dd) {int I; for (I = 0; I <m; I ++) {If (Map [DD] [I] = 1 & VT [I] = 0) {vt [I] = 1; if (link [I] =-1 | DFS (link [I]) {link [I] = dd; return 1 ;}} return 0 ;} int main () {int I, j, k; d Ouble DIS; double GG; while (scanf ("% d % lf", & N, & M, & S, & V )! = EOF) {for (I = 0; I <n; I ++) {scanf ("% lf", & Q [I]. x, & Q [I]. y) ;}for (I = 0; I <m; I ++) {scanf ("% lf", & W [I]. x, & W [I]. y);} Gg = S * V; memset (MAP, 0, sizeof (MAP); memset (link,-1, sizeof (Link )); for (I = 0; I <n; I ++) {for (j = 0; j <m; j ++) {Dis = SQRT (W [J]. x-Q [I]. x) * (W [J]. x-Q [I]. x) + (W [J]. y-Q [I]. y) * (W [J]. y-Q [I]. y); If (DIS <= GG) {map [I] [J] = 1 ;}} int CNT = 0; for (I = 0; I <N; I ++) {memset (Vt, 0, sizeof (VT); CNT + = DFS (I);} printf ("% d \ n ", n-CNT);} return 0 ;}