POJ-2536 Gopher II binary graph maximum matching

Source: Internet
Author: User
Tags gopher

The main problem: There are n mice, m holes, a hole can only hide a mouse.
There was a flock of eagles, and the mice had to hide in the cave before they could be taken away.
Now give the coordinates of each mouse, the coordinates of each hole, the speed of the mouse, and the time the eagle catches the mouse, asking the eagle to catch a few mice at least.

How to solve the problem: find the distance between each mouse and each hole, and then, in addition to the speed of the mouse, see whether the eagle catches the mouse in time to run into the hole.
Then divide the mouse and the hole into two point sets, the maximum match of the binary graph, and then the N-Max match is the number of mice the eagle can catch at least.

#include <cstdio>#include <cstring>#include <cmath>using namespace STD;Const intN = the;Const DoubleESP =1e-7;DoubleDis[n][n], pos[n][2], hole[n][2];intG[n][n], Vis[n], link[n], N, M, S, v;DoubleDistanceDoubleX1,DoubleX2,DoubleY1,Doubley2) {return sqrt((X1-X2) * (X1-X2) + (y1-y2) * (Y1-y2));voidInit () { for(inti =0; I < n; i++)scanf("%LF%LF", &pos[i][0], &pos[i][1]); for(inti =0; I < m; i++)scanf("%LF%LF", &hole[i][0], &hole[i][1]);memset(g,0,sizeof(g)); for(inti =0; I < n; i++) for(intj =0; J < M; J + +) {Dis[i][j] = distance (pos[i][0], hole[j][0], pos[i][1], hole[j][1]);if(Dis[i][j]/v-s <= ESP) G[I][J] =1; }memset(Link,-1,sizeof(link));}BOOLDfsintu) { for(inti =0; I < m; i++) {if(Vis[i] | |!g[u][i])Continue; Vis[i] =1;if(Link[i] = =-1|| DFS (Link[i])) {Link[i] = u;return true; }    }return false;}voidHungary () {intAns =0; for(inti =0; I < n; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", N-ans);}intMain () { while(scanf("%d%d%d%d", &n, &m, &s, &v)! = EOF) {init ();    Hungary (); }return 0;}

POJ-2536 Gopher II binary graph maximum matching

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.