Gopher II (Hungarian algorithm template)

Source: Internet
Author: User
Tags gopher

Describe

The Gopher family, having averted of the canine threat, must face a new predator.

The is 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's vulnerable to being eaten. A hole can save at the 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 all 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 is in metres; All times is in seconds; All velocities is in metres per second.

Output

Output consists of a, giving the number of vulnerable Gophers.

Sample input

2 2 5 10
1.0 1.0
2.0 2.0
100.0 100.0
20.0 20.0

Sample output

1

The eagle catches the mouse, n mouse, M hole, each hole can hold only one mouse, speed is V, safe distance is s*v, asks to be eaten the mouse, uses the Hungarian algorithm

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <cmath>5 using namespacestd;6 7 intn,m,s,v;8 structDis9 {Ten     Doublex, y; One}gop[ the],hol[ the];//the position of the mouse, the hole A intflag[ the],par[ the];//whether the hole matches, the hole matches the mouse -  - intMatchintu) the { -     DoubleLen; -      for(intI=1; i<=m;i++){ -Len=sqrt ((gop[u].x-hol[i].x) * (gop[u].x-hol[i].x) + (GOP[U].Y-HOL[I].Y) * (gop[u].y-hol[i].y)); +         if(len-s*v*1.0<1e-6&&!flag[i]) {//can reach the forward hole in the eagle and does not match in this match -flag[i]=1;//Match +             if(!par[i]| | Match (Par[i])) {//the hole has no mice or can safely transfer the hole's mouse to another hole. APar[i]=u;//into the hole at                 return 1; -             } -         } -     } -     return 0; - } in  - intMain () to { +      while(SCANF ("%d%d%d%d", &n,&m,&s,&v)! =EOF) { -          for(intI=1; i<=n;i++){ thescanf"%LF%LF",&gop[i].x,&gop[i].y); *         } $          for(intI=1; i<=m;i++){Panax Notoginsengscanf"%LF%LF",&hol[i].x,&hol[i].y); -         } the         intsum=0; +memset (PAR,0,sizeof(PAR)); A          for(intI=1; i<=n;i++){ thememset (Flag,0,sizeof(flag));//Initialize each time +sum+=match (i); -         } $printf"%d\n", N-sum); $     } -     return 0; -}

Gopher II (Hungarian algorithm template)

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.