Missile Time limit: 2 Seconds Memory Limit: 65536 KB
You control N missile launching towers. The Every tower has a enough missiles, but a for each tower is only one missile can is launch at the same time. Before the launching, every missile need T1 seconds to leave the tower. Assume that all the missiles has the same speedV, and it would 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 need T2 minutes to prepare for the next one.
Now, give you the coordinate position of N missile launching towers andM targets,T1,T2 and V, you should find the minimum minutes to destroy all the targets.
Input
The input would consist of about ten cases. The first line of all case contains five positive integer numbersN,M,T1, T2 and V , decribed as above. The nextm lines contains the numbers indicating the coordinate ofm targets. The continueingn lines contains is the indicating ofn coordinate of the integer numbers towers.
To all the cases, 1≤ N ≤ 50, 1≤ M ≤50
The absolute value of all the coordinates would not exceed 10000, T1,T2,V would not exceed 2000.
Output
For each case, the output was only one line containing only one real number with six digits precision (after a decimal poin T) 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
Test instructions: attacking m targets with N missile towers. Each missile tower can only serve a single missile at the same time, after launching a missile, it takes T1 (in seconds) to leave the current missile tower, and a missile from the time it was launched to hitting the target is related to the distance from the target to the launch tower (straight distance), After each missile launch, the launch tower needs T2 time to prepare for the next one. Now give the position coordinates of N missile towers and M targets, and t1,t2,v, and ask how much time it takes for this N missile launch tower to destroy all m targets at least.
Specific implementation
One: For each missile launcher, it hits a target with a total of M cases: the first launch, the second launch, the third launch in the Tower, respectively ... Until the first m launch. So we can split each of the missile towers into M towers, which are the same distance from the same target, the only difference being that T1 and T2 are not the same.
Two: So we get the n*m point launcher to the M target mapping, the relationship is the current launch tower hit target time-consuming.
Three: Set up super Source point 0, Super meeting point N * m + M + 1.
Four: The super source points to each target a capacity of 1 side, each tower (split) to the super meeting point of a capacity of 1 edge, press if the relationship is less than the current query time (with matching build edge) build capacity of 1.
Then run the maximum flow to determine if the maximum flow is M. Then two points to find.
The above analysis from Yu elder brother's blog: Laugh to walk the road of their own
Laugh and walk through your
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath > #define INF 0x3f3f3f3f#define maxn 5000#define maxm 500000using namespace Std;int HEAD[MAXN], CUR[MAXN], Cnt;int dist[ MAXN], vis[maxn];struct node {int u, V, cap, flow, next;}; struct node{double x, y;}; Node EDGE[MAXM]; NODE tower[60]; Node Target[60];int N, M;double T1, T2, v;double map[60][60];d ouble time[3000][60];d ouble Change (Node A, Node B) {return sq RT ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y)); void init () {cnt = 0;memset (head,-1, sizeof (head));} void Add (int u, int v, int w) {node E1 = {u, V, W, 0, head[u]};edge[cnt] = e1;head[u] = Cnt++;node E2 = {V, u, 0, 0, head[v ]};EDGE[CNT] = e2;head[v] = cnt++;} void Getmap (double max_min) {int I, j;for (i = 1; I <= N * M; ++i) Add (0, I, 1); for (i = n * m + 1; I <= n * m + m; ++i) Add (i, N * m + M + 1, 1), for (i = 1; I <= n * M; ++i) for (j = 1; j <= M; ++j) if (Time[i][j] <= max_min) Add (i, J + N) * M, 1);} BOOL BFS (int st, int ed) {queue<int>q; memset (Vis, 0, sizeof (VIS)); memset (Dist,-1, sizeof (Dist)); Q.push (ST); VIS[ST] = 1; DIST[ST] = 0; while (!q.empty ()) {int u = q.front (); Q.pop (); for (int i = head[u]; i =-1; i = Edge[i].next) {node E = Edge[i]; if (!VIS[E.V] && e.cap > E.flow) {vis[e.v] = 1; DIST[E.V] = Dist[u] + 1; if (e.v = = ed) return true; Q.push (E.V); }}} return false; } int DFS (int x, int ed, int a) {if (a = = 0 | | x = = ed) return A; int flow = 0, F; for (int &i = cur[x]; I! =-1; I =edge[i].next) {node &e = Edge[i]; if (dist[e.v] = = Dist[x] + 1 && (f = DFS (e.v, ed, Min (A, e.cap-e.flow))) > 0) {e.flow + = f; edge[i ^ 1].flow-= f; Flow + + F; A-= f; IfA = = 0) break; }} return flow; } int Maxflow (int st, int ed) {int flowsum = 0; while (BFS (St, ed)) {memcpy (cur, head, sizeof (head)); Flowsum + = DFS (St, Ed, INF); } return flowsum; } int main () {while (scanf ("%d%d%lf%lf%lf", &n, &m, &t1, &T2, &v)! = EOF) {T1 = T1/60;int I, J, k;for (j = 1; j <= M; ++j) scanf ("%lf%lf", &target[j].x, &target[j].y); for (i = 1; I <= N; ++i) scanf ("%lf%lf", & tower[i].x, &TOWER[I].Y); for (i = 1; I <= N; ++i) for (j = 1; j <= M; ++j) map[i][j] = Change (Tower[i], target[j]); f or (i = 1; I <= N; ++i) for (k = 1, k <= M; ++k) {for (j = 1; j <= M; ++j) time[(i-1) * M + k][j] = T1 * k + T2 * (k -1) + map[i][j]/V;} Double L = 0.0, r = 200000000000.0, Mid;while (r-l >= 1e-8) {mid = (L + R)/2;init (); Getmap (mid); if (Maxflow (0, N * M + M + 1) >= m) r = mid;else L = mid;} printf ("%.6lf\n", r);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ZOJ 3640--missile "Two-point search && maximum flow dinic && Classic Maps"