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> ...
随机推荐
- js检测对象中是否存在某个属性
1.使用in关键字.该方法可以判断对象的自有属性和继承来的属性是否存在. 2.使用对象的hasOwnProperty()方法.该方法只能判断自有属性是否存在,对于继承属性会返回false. 3.用un ...
- 用PhotoSwipe制作相册,手势可放大
1.引入css和js <link href="css/photoswipee.css" rel="stylesheet" type="text/ ...
- vue 相对其他热门 框架 优点 --- 待续
react vs vue 1. 处理动画 vue 更有优势 , 这是由于 React 有大量的检查机制 2.性能更高, 在React中,你需要在每个地方去实现 shouldComponentUpda ...
- redis12--常用API
上一篇总结我们使用我们本地的Eclipse中创建的jedis工程,链接到了我们处于VMware虚拟机上的Linux系统上的Redis服务,我们接下来讲一下jedis的一些常用的API.(1)jedis ...
- OGG中断后,重新同步操作
模拟一下goldengata中断后,重新同步操作: 1.关掉源端抽取进程 GGSCI (20081122-2105) 15> info all Program Status Group Lag ...
- 【第四篇】Volley修改之GsonRequest
json解析工具类的引入,这里引用lite马天宇的解析json的工具类: public class GsonImpl extends Json { private Gson gson = new Gs ...
- 手机端跳转和pc端跳转
http://jingyan.baidu.com/article/cdddd41c61823e53cb00e198.html 参考网址 浏览:11532 | 更新:2014-04-22 16:51 第 ...
- hdu_5879_Cure(打表)
题目链接:hdu_5879_Cure 题意: 给你一个n,让你计算1/k2的和,k从1到n. 题解: 因为只保留5位小数,所以打个100W的表,比这个数大的直接输出最后一位就行了 #include&l ...
- LeetCode OJ 121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- chapter 12_1 数据文件
Lua的一个重要特性,就是可以作为配置文件,利用到table构造式来定义一种文件格式. 只需要在写数据时做一点额外的工作,读取数据就会变得相当容易.也就是将数据作为Lua代码输出. 当运行这些代码时, ...