POJ 2536 Gopher II
二分图的最大匹配
地鼠内部和地鼠洞内部都是没有边相连的,那么就可以看成一个二分图。地鼠如果可以跑到那个地鼠洞,就连一条边,然后跑二分图的最大匹配,最后地鼠的数量减去最大匹配数就是答案。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int MAXN=;
int nx,ny;
int g[MAXN][MAXN];
int cx[MAXN],cy[MAXN];
int mk[MAXN];
int n;
double s,v;
double H=1e-; struct P
{
double x,y;
} M[MAXN],D[MAXN]; int path(int u)
{
for(int v=; v<ny; v++)
{
if(g[u][v]&&!mk[v])
{
mk[v]=;
if(cy[v]==-||path(cy[v]))
{
cx[u]=v;
cy[v]=u;
return ;
}
}
}
return ;
} int MaxMatch()
{
int res=;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
for(int i=; i<nx; i++)
{
if(cx[i]==-)
{
memset(mk,,sizeof(mk));
res=res+path(i);
}
}
return res;
} bool ok(const P&a,const P&b)
{
if(s*v-sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))>=H)
return ;
return ;
} int main()
{
int i,j;
while(~scanf("%d%d%lf%lf",&nx,&ny,&s,&v))
{
memset(g,,sizeof(g));
for(i=; i<nx; i++)
scanf("%lf%lf",&M[i].x,&M[i].y);
for(i=; i<ny; i++)
scanf("%lf%lf",&D[i].x,&D[i].y);
for(i=; i<nx; i++)
for(j=; j<ny; j++)
if(ok(M[i],D[j]))
g[i][j]=;
printf("%d\n",nx-MaxMatch());
}
return ;
}
POJ 2536 Gopher II的更多相关文章
- poj 2536 Gopher II (二分匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6345 Accepted: 2599 Descrip ...
- POJ 2536 Gopher II (ZOJ 2536) 二分图匹配
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1882 http://poj.org/problem?id=2536 题目大 ...
- POJ 2536 Gopher II(二分图的最大匹配)
题目链接:http://poj.org/problem?id=2536 题意:已知有n仅仅老鼠的坐标,m个洞的坐标,老鼠的移动速度为V,S秒以后有一仅仅老鹰要吃老鼠,问有多少个老鼠被吃. 非常明晰,二 ...
- POJ 2536 Gopher II(二分图最大匹配)
题意: N只地鼠M个洞,每只地鼠.每个洞都有一个坐标. 每只地鼠速度一样,对于每只地鼠而言,如果它跑到某一个洞的所花的时间小于等于S,它才不会被老鹰吃掉. 规定每个洞最多只能藏一只地鼠. 问最少有多少 ...
- [POJ 2536] Gopher ||
[题目链接] http://poj.org/problem?id=2536 [算法] 匈牙利算法解二分图最大匹配 [代码] #include <algorithm> #include &l ...
- POJ 2536 之 Gopher II(二分图最大匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6675 Accepted: 2732 Descrip ...
- POJ2536 Gopher II(二分图最大匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9005 Accepted: 3724 Descrip ...
- 2018.07.06 POJ2536 Gopher II(二分图匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Description The gopher family, having averted the ...
- 二分图最大匹配(匈牙利算法) UVA 10080 Gopher II
题目传送门 /* 匈牙利算法:这题比UVA_670简单,注意是要被吃的鼠的最少个数,套模板 */ #include <cstdio> #include <algorithm> ...
随机推荐
- ios 显示其他app的购买页面
using UnityEngine; using System.Collections; using System.Runtime.InteropServices ; public class IOS ...
- Linux安装mysql mysql5.5.40 <NIOT>
一. 操作系统与软件 操作系统及版本 Centos 6.4 依赖包 gcc.gcc-c++.cmake.ncurses-devel 下载目录 /opt Mysql安装目录 /usr/local/ ...
- 在eclipse中maven web项目部署到tomcat,访问不了
修改eclipse中tomcat发布路径后,能正常访问
- 二.创建maven工程及下载需要的jar包
1.使用Eclipse的Maven插件来创建一简单的Maven项目 步骤:打开新建项目对话框,选择Maven Project(File->New->Object->Maven-> ...
- Android: Failure [INSTALL_FAILED_DEXOPT] and Failure [INSTALL_FAILED_UID_CHANGED] 解决方案
1. 错误: Failure [INSTALL_FAILED_DEXOPT] Android安装App时 D:\WorkSpace\Administrator\workspace\svn\soot ...
- jQuery(5)——动画
jQuery中的动画 [show()方法和hide()方法] 在HTML文档中,为一个元素调用hide()方法,会将该元素的display样式改为“none”,show()方法将元素的display样 ...
- Python第一天课程
1.在linux下写python脚本,开头的解释器宣告的写法应该是#!/usr/bin/env python 定义变量name="XXX" age=21 所有使用引号引起的内 ...
- UITextField 设置 placeholder 的字体颜色方法
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; color: #ff2608 } [_textField setValu ...
- 第三节,入门知识和windows系统安装python环境
1.使用Linux的好处(稳定)不容易死机,可以长达几年不间断运行(安全)相对windows系统更安全,相对更不容受到各种攻击(开源)免费使用2.安装好虚拟机VMware软件,和Linux系统,以及X ...
- MVC中的Startup.Auth.cs、BundleConfig.cs、FilterConfig.cs和RouteConfig.cs
一.MVC中的Startup.Auth.cs.BundleConfig.cs.FilterConfig.cs和RouteConfig.cs四个文件在app_start中 <1>Bundle ...