Zoj 3460 Missile

Source: Internet
Author: User
Tags integer numbers

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 speed V, 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 and M 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 numbers N, M, T1, T2 and v, decribed as above. The next m lines contains the numbers indicating the coordinate of m targets. The continueing n lines contains is the indicating of n 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 excee D 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
#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, &AMP;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, &AMP;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;}

  

Zoj 3460 Missile

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.