POJ 2536 Gopher II(二分图最大匹配)
来源:互联网 发布:falsh 小游戏制作软件 编辑:程序博客网 时间:2024/05/16 01:25
题目地址
题意:n只地鼠,m个洞,老鹰的到达地面的时间s,地鼠的移动速度v,求多少只地鼠会被老鹰吃了。
思路:直接暴力枚举每个地鼠到哪些洞不会被老鹰吃掉,因为每个洞只能有一只地鼠,所以求出的最大匹配就是不被老鹰吃掉的地鼠个数,然后用n减去就好了。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define N 2010#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1e9 + 7;int n, m;struct node{ double x, y;}gopher[N], gopher_holes[N];struct Hungarian { vector<int> mapp[N]; bool vis[N];//是否为匹配点 int mark[N];//该边与哪个点构成的边为匹配边 void init() { for (int i = 0; i <= n + m + 20; i++) { mapp[i].clear(); } memset(mark, -1, sizeof(mark)); } void add(int a, int b) { mapp[a].push_back(b); mapp[b].push_back(a); } bool dfs(int u) { for (int i = 0; i < mapp[u].size(); i++) { int v = mapp[u][i]; if (!vis[v]) { vis[v] = true; if (mark[v] == -1 || dfs(mark[v])) { mark[u] = v; mark[v] = u; return true; } } } return false; } int solve() { int sum = 0; for (int i = 1; i <= n; i++) {//枚举非匹配点 if (mark[i] == -1) { memset(vis, false, sizeof(vis)); if (dfs(i)) { sum++;//最大匹配的个数 } } } return sum; }}hungarian;double dis(node p1, node p2){ return sqrt((p2.x - p1.x)*(p2.x - p1.x) + (p2.y - p1.y)*(p2.y - p1.y));}int main() { int a, b, c; int s, v; cin.sync_with_stdio(false); while (cin >> n >> m >> s >> v) { hungarian.init(); for (int i = 1; i <= n; i++) { cin >> gopher[i].x >> gopher[i].y; } for (int i = 1; i <= m; i++) { cin >> gopher_holes[i].x >> gopher_holes[i].y; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { double lens = dis(gopher_holes[j], gopher[i]); if (lens / v <= (double)s) { hungarian.add(i, n + j); } } } cout << n - hungarian.solve() << endl; } return 0;}
阅读全文
0 0
- 【二分图+最大匹配】北大 poj 2536 Gopher II
- POJ 2536 Gopher II(二分图最大匹配)
- POJ 2536 Gopher II(二分图最大匹配)
- POJ 2536 Gopher II(二分图的最大匹配)
- poj 2536 Gopher II 二分图最大匹配
- POJ 2536 Gopher II (二分图求最大匹配)
- POJ - 2536 Gopher II 二分图 最大匹配
- POJ 2536 Gopher II (二分图最大匹配)
- POJ 2536 Gopher II(二分图最大匹配)
- poj 2536 Gopher II(二分图最大匹配,构图)
- POJ 2536 Gopher II(二分图最大匹配)
- POJ 2536 Gopher II(二分图最大匹配)
- POJ-2536 Gopher II(二分图最大匹配)
- POJ 2536 - Gopher II(二分图匹配)
- POJ 2536 Gopher II 二分图匹配
- POJ2536 Gopher II【二分图最大匹配】
- Gopher II(二分图最大匹配)
- POJ2536 Gopher II(二分图最大匹配)
- Java web学习笔记之MySQL数据库
- Spring Data JPA 简单查询--接口方法
- 多线程编程
- AjaxJquery 加载不了本地文件--allow-file-access-from-files
- Android 加载本地图片decodeStream()方法OOM
- POJ 2536 Gopher II(二分图最大匹配)
- H5随笔第二课
- HTML笔记(二)bootstrap之排版
- 杨辉三角 python实现
- 关于使用FragmentPagerAdapter时,滑动有顿卡现象的解决办法
- Dialog
- Java的clone方法--深拷贝和浅拷贝
- 50. Pow(x, n)
- oracle---function