Missile
Time Limit: 2 Seconds Memory Limit: 65536 KB
You controlNMissile launching towers. Every tower has enough missiles, but for each tower only one missile can be launch at the same time. Before the launching, every missile needT1Seconds to leave the tower. Assume that all the missiles have the same speedV, And it woshould fly along the shortest path to the target. you can just consider the horizontal distance and ignore the height. you can consider the time equal to distance/V (minutes ). the missile can immediately destroy the target when it reached. besides, for the same tower, after launching a missile, it needT2Minutes to prepare for the next one.
Now, give you the coordinate positionNMissile launching towers andMTargets,T1,T2AndV, You shoshould find the minimum minutes to destroy all the targets.
Input
The input will consist of about 10 cases. The first line of each case contains five positive integer numbersN,M,T1,T2AndV, Decribed as abve. The nextMLines contains two integer numbers indicating the coordinateMTargets. The continueingNLines contains two integer numbers indicating the coordinateNTowers.
To all the cases, 1 ≤N≤ 50, 1 ≤M≤ 50
The absolute value of all the coordinates can not exceed 10000,T1,T2,VWill not exceed 2000.
Output
For each case, the output is only one line containing only one real number with six digits precision (after a decimal point) indicating the minimum minutes to destroy all the targets.
Sample Input
3 3 30 20 10 00 5050 050 500 10001000 0
Sample Output
91.500000
Author:HE, Ningxu
Contest:ZOJ Monthly, January 2011
First, you must carefully understand the subject.
It takes time for each tower to launch a missile at T1 for N missile bases to launch M targets. Then, after T2.
It's amazing to solve this problem with a binary + binary match ~~~~~
How nice it is to use the binary matching method efficiently.
To be expanded to M x N missile launch bases. The time limit of the Second Part. Create a graph and obtain the maximum matching value.
Code:
/* General question: Use n missile towers to attack m targets. Each launch frame can only serve a missile at a certain time. It takes time for a missile to be launched to prepare t1. The time for a missile to launch to hit the target depends on the distance from the target to the launch frame. After each missile is launched, it takes T2. Now, I want to explain how much time is required to destroy all m targets. General idea: the minimum value of the maximum time of the binary enumeration. The bipartite graph is constructed based on the enumeration time each time, and the maximum matching is obtained to determine whether the enumerated value meets the requirements. Note that unit T1 must be divided into */# include <stdio. h> # include <string. h> # include <iostream> # include <algorithm> # include <math. h ># include <vector> using namespace std; const double eps = 1e-8; const int MAXN = 2550; int linker [MAXN]; bool used [MAXN]; vector <int> g [60]; int uN; bool dfs (int u) {for (int I = 0; I <g [u]. size (); I ++) {if (! Used [g [u] [I]) {used [g [u] [I] = true; if (linker [g [u] [I] =-1 | dfs (linker [g [u] [I]) {linker [g [u] [I] = u; return true ;}}return false ;}int hungary () {int u; int res = 0; memset (linker,-1, sizeof (linker); for (u = 0; u <uN; u ++) {memset (used, false, sizeof (used )); if (dfs (u) res ++;} return res;} int N, M; double T1, T2, V; struct Node {int x, y ;}; node node1 [60], node2 [60]; double d [60] [60]; double tt [MAXN] [60]; doubl E dis (Node a, Node B) {return sqrt (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} void init () {for (int I = 0; I <N; I ++) for (int j = 0; j <M; j ++) d [I] [j] = dis (node1 [I], node2 [j]); for (int k = 0; k <M; k ++) for (int I = 0; I <N; I ++) for (int j = 0; j <M; j ++) {tt [I * M + k] [j] = k * T2 + (k + 1) * T1 + d [I] [j]/V ;} uN = M;} double solve () {double l = 0; double r = 200000000000.0; double mid; while (r-l> = eps) {mid = (l + r) /2; for (int I = 0; I <M; I ++) g [I]. clear (); For (int I = 0; I <M * N; I ++) for (int j = 0; j <M; j ++) {if (tt [I] [j] <= mid) g [j]. push_back (I);} if (hungary () = M) {r = mid;} else l = mid;} printf ("%. 6lf \ n ", r);} int main () {// freopen (" in.txt "," r ", stdin); // freopen (" out.txt ", "w", stdout); while (scanf ("% d % lf", & N, & M, & T1, & T2, & V )! = EOF) {T1/= 60; // note that the answer is not always lost except for (int I = 0; I <M; I ++) scanf ("% d", & node2 [I]. x, & node2 [I]. y); for (int I = 0; I <N; I ++) scanf ("% d", & node1 [I]. x, & node1 [I]. y); init (); solve ();} return 0 ;}