标签:二分查找
以每一个可以放车的点的行列坐标为点,建图,然后求最大匹配
接下来,删边,观察最大匹配是否改变,如果改变,这个点就是关键点
/*************************************************************************
> File Name: hdu1281.cpp
> Author: ALex
> Mail: zchao1995@gmail.com
> Created Time: 2015年02月16日 星期一 18时01分44秒
************************************************************************/
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
const int N = 110;
int edge[N][N];
int un, vn, n, m;
int match[N];
bool used[N];
struct node
{
int x, y;
}imp[N * N];
bool dfs (int u)
{
for (int i = 1; i <= vn; ++i)
{
if (edge[u][i] && !used[i])
{
used[i] = 1;
if (match[i] == -1 || dfs (match[i]))
{
match[i] = u;
return 1;
}
}
}
return 0;
}
int hungry ()
{
memset (match, -1, sizeof(match));
int ans = 0;
for (int i = 1; i <= un; ++i)
{
memset (used, 0, sizeof(used));
if (dfs(i))
{
++ans;
}
}
return ans;
}
int main ()
{
int k;
int icase = 1;
while (~scanf("%d%d%d", &n, &m, &k))
{
memset (edge, 0, sizeof(edge));
for (int i = 1; i <= k; ++i)
{
scanf("%d%d", &imp[i].x, &imp[i].y);
edge[imp[i].x][imp[i].y] = 1;
}
un = n;
vn = m;
int ans = hungry();
int ret = 0;
for (int i = 1; i <= k; ++i)
{
edge[imp[i].x][imp[i].y] = 0;
if (hungry() != ans)
{
++ret;
}
edge[imp[i].x][imp[i].y] = 1;
}
printf("Board %d have %d important blanks for %d chessmen.\n", icase++, ret, ans);
}
return 0;
}
标签:二分查找
原文地址:http://blog.csdn.net/guard_mine/article/details/43853647