poj 2536 Gopher II 最大匹配
来源:互联网 发布:mac osx 切换root 编辑:程序博客网 时间:2024/05/22 00:34
题目
题目链接:http://poj.org/problem?id=2536
题目来源:http://www.cnblogs.com/vongang/archive/2012/02/21/2361882.html
题解
最小化死掉的人,也就是最大化存活的人。
人和洞建二分图,根据题中信息算出某人对于某个洞是否能够到达,能到达就连上边。
图上的最大匹配的规模就是最多的存活的人,
n−|M| 就是答案。
代码
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define fi first#define se secondusing namespace std;typedef long long LL;typedef pair<int,int> PII;typedef pair<double, double> pdd;// headconst int N = 105;const int M = N;const int E = N * M;struct Gragh { struct Edge { int to, nxt; Edge(int to, int nxt) : to(to), nxt(nxt) {} Edge() {} }; Edge e[E]; int head[N], match[M], ec; bool vis[N]; void addEdge(int from, int to) { e[ec] = Edge(to, head[from]); head[from] = ec++; } void init(int n, int m) { ec = 0; for (int i = 0; i <= n; i++) head[i] = -1; for (int i = 0; i <= m; i++) match[i] = -1; } bool dfs(int x) { vis[x] = true; for (int i = head[x]; ~i; i = e[i].nxt) { int to = e[i].to, w = match[to]; if (w == -1 || (!vis[w] && dfs(w))) { match[to] = x; return true; } } return false; } int bipatiteMatch(int n) { int ans = 0; for (int i = 0; i < n; i++) { memset(vis, 0, sizeof vis); if (dfs(i)) ans++; } return ans; }};inline double sq(double x) { return x * x;}double dis(pdd &a, pdd &b) { return sqrt(sq(a.fi - b.fi) + sq(a.se - b.se));}Gragh g;pdd a[N], b[N];int main() { int n, m, s, v; while (scanf("%d%d%d%d", &n, &m, &s, &v) == 4) { s *= v; g.init(n, m); for (int i = 0; i < n; i++) { scanf("%lf%lf", &a[i].fi, &a[i].se); } for (int i = 0; i < m; i++) { scanf("%lf%lf", &b[i].fi, &b[i].se); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (dis(a[i], b[j]) > s) continue; g.addEdge(i, j); } } printf("%d\n", n - g.bipatiteMatch(n)); } 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(二分图最大匹配)
- POJ 2536 Gopher II 二分匹配
- 【POJ】2536 Gopher II 二分匹配
- POJ 2536 - Gopher II(二分图匹配)
- 3求最大字串和
- Activity的三种关闭方法分析(finish;onDestory;exit)
- UIscrollView
- 分段和分页
- java面试中遇到的问题
- poj 2536 Gopher II 最大匹配
- hustoj 昂贵的聘礼
- Javascript复习第三天动态显示时间
- 1022
- NYOJ 27 水池数目(深搜)
- redis学习笔记(18)---事件
- Leetcode 237. Delete Node in a Linked List
- gdb 调试利器
- Tableau Desktop简单介绍