POJ 2536 Gopher II(二分图的最大匹配)

题目链接:http://poj.org/problem?id=2536

题意:已知有n只老鼠的坐标,m个洞的坐标,老鼠的移动速度为V,S秒以后有一只老鹰要吃老鼠,问有多少个老鼠被吃。

很明晰,二分匹配,老鼠为X集合,洞为Y集合

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#define init(a) memset(a,0,sizeof(a))
#define PI acos(-1,0)
using namespace std;
const int maxn = 310;
const int maxm = 100001;
#define lson left, m, id<<1
#define rson m+1, right, id<<1|1
#define min(a,b) (a>b)?b:a
#define max(a,b) (a>b)?a:b
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,m,s,v,ma[500][500];
bool vis[500];
int line[500];
struct node
{
  double x,y;
};
node g[300],h[300];

int DFS(int u)
{
  for(int v = 1;v<=m;v++)
    {
    if(!vis[v]&&ma[u][v])
    {
      vis[v]=1;
      if(line[v]==-1 || DFS(line[v]))
    {
        line[v] = u;
        return 1;
      }
    }
  }
  return 0;
}
int K_M()
{
    memset(line,-1,sizeof(line));
    int ans=0;
    for(int i = 1;i<=n;i++)
    {
      init(vis);
      ans += DFS(i);
    }
    return ans;
}
int main()
{
  while(scanf("%d%d%d%d",&n,&m,&s,&v)!=EOF)
    {
    init(ma);
    for(int i=1;i<=n;i++)
    {
      scanf("%lf%lf",&g[i].x,&g[i].y);
    }
    for(int i=1;i<=m;i++)
    {
      scanf("%lf%lf",&h[i].x,&h[i].y);
    }
    for(int i=1;i<=n;i++)
    {
      for(int j=1;j<=m;j++)
        {
  double dis = sqrt((h[j].x-g[i].x)*(h[j].x-g[i].x)+(h[j].y-g[i].y)*(h[j].y-g[i].y));//老鼠与洞的距离

        if(dis / v <= (double)s)//老鼠到达洞的时间<S
            {
                ma[i][j] = 1;
            }
        }
    }
    int ans = K_M();
    printf("%d\n",n - ans);
  }
  return 0;
}

POJ 2536 Gopher II(二分图的最大匹配),布布扣,bubuko.com

时间: 2024-11-07 23:52:05

POJ 2536 Gopher II(二分图的最大匹配)的相关文章

POJ - 2536 Gopher II 二分图 最大匹配

题目大意:有n只老鼠,m个洞,一个洞只能藏一只老鼠. 有一群鹰来了,老鼠们要赶紧躲到洞里才不会被抓走. 现在给出每只老鼠的坐标,每个洞的坐标,老鼠的速度,和鹰捉到老鼠的时间,问鹰最少能抓到几只老鼠 解题思路:求出每只老鼠和每个洞之间的距离,然后除于老鼠的速度,看在鹰捉到老鼠的时间内能否跑到该洞中. 然后将老鼠和洞分成两个点集,进行二分图的最大匹配,然后n-最大匹配就是鹰至少能抓到的老鼠的数量了 #include<cstdio> #include<cstring> #include&

POJ 2536 Gopher II

二分图的最大匹配 地鼠内部和地鼠洞内部都是没有边相连的,那么就可以看成一个二分图.地鼠如果可以跑到那个地鼠洞,就连一条边,然后跑二分图的最大匹配,最后地鼠的数量减去最大匹配数就是答案. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int MAXN=505; int nx,ny; int g[MAXN][MAX

poj 2536 Gopher II (二分匹配)

Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6345   Accepted: 2599 Description The gopher family, having averted the canine threat, must face a new predator. The are n gophers and m gopher holes, each at distinct (x, y) coor

POJ 2536 Gopher II(二分图最大匹配)

题意: N只地鼠M个洞,每只地鼠.每个洞都有一个坐标. 每只地鼠速度一样,对于每只地鼠而言,如果它跑到某一个洞的所花的时间小于等于S,它才不会被老鹰吃掉. 规定每个洞最多只能藏一只地鼠. 问最少有多少只地鼠会命丧鹰口. 思路: 直接建图.二分图最大匹配. 代码: char st[105]; char Range[25][5]; int n; int num[10]; int cx[25],cy[205]; bool bmask[205]; vector<int> graph[25]; int

poj 1274(网络流解二分图的最大匹配)

The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22539   Accepted: 10072 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering p

POJ #3041 Asteroids 3041 二分图最小覆盖 最大匹配 匈牙利算法

Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the

Poj_2536 Gopher II -二分图建图

题目:有m个洞,n知动物,每个洞容一知动物,问当天敌来后最少有多少知动物不能逃亡. 没看清楚最后的输出,被坑了几发 /************************************************ Author :DarkTong Created Time :2016/7/31 16:12:15 File Name :Pos_2536.cpp *************************************************/ //#include <bits/

POJ 1274-The Perfect Stall(二分图_最大匹配)

The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19272   Accepted: 8737 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr

POJ 2536 之 Gopher II(二分图最大匹配)

Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6675   Accepted: 2732 Description The gopher family, having averted the canine threat, must face a new predator. The are n gophers and m gopher holes, each at distinct (x, y) coor