以行列为点建图,每个点(x,y) 对应一条边连接x,y。二分图的最小点覆盖=最大匹配

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI 3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else freopen("data.in","r",stdin);
// freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
int ch;
while((ch=getchar())!=EOF) {
if(ch!=' '&&ch!='\n')return ch;
}
return EOF;
} const int maxn = ;
vector<int> g[maxn];
int n, m;
void Init()
{
for(int i=; i<=n; i++)
g[i].clear();
} void add(int u, int v)
{
g[u].push_back(v);
} int match[maxn];
int vis[maxn]; bool dfs(int u)
{
vis[u] = true;
for(int i = ; i < g[u].size(); i++)
{
int v = g[u][i];
int w = match[v];
if(w<||!vis[w]&&dfs(w))
{
match[u] = v;
match[v] = u;
return true;
}
}
return false;
}
int solve()
{
memset(match,-,sizeof(match));
int res = ;
for(int u=; u <= n; u++)
{
if(match[u]<)
{
memset(vis, , sizeof(vis));
if(dfs(u))
res++;
}
}
return res;
}
int main()
{
debug();
while(scanf("%d%d", &n, &m) != EOF)
{
for(int i=; i<=m; i++)
{
int u,v;
scanf("%d%d", &u, &v);
add(u, v+n);
add(v+n, u);
} printf("%d\n",solve());
}
return ;
}

POJ 3041 Asteroids 二分图匹配的更多相关文章

  1. POJ 3041 Asteroids 二分图

    原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  2. POJ 3041 Asteroids (二分图最小点覆盖)

    题目链接:http://poj.org/problem?id=3041 在一个n*n的地图中,有m和障碍物,你每一次可以消除一行或者一列的障碍物,问你最少消除几次可以将障碍物全部清除. 用二分图将行( ...

  3. poj 3041 Asteroids (二分图的最大匹配 第一题)

    题目:http://poj.org/problem?id=3041 题意:在某个n*n的空间内,分布有一些小行星,某人在里面打炮,放一枪后某一行或某一列的行星就都没了,让求最少的打炮数. 然后把每行x ...

  4. poj - 3041 Asteroids (二分图最大匹配+匈牙利算法)

    http://poj.org/problem?id=3041 在n*n的网格中有K颗小行星,小行星i的位置是(Ri,Ci),现在有一个强有力的武器能够用一发光速将一整行或一整列的小行星轰为灰烬,想要利 ...

  5. 【网络流#6】POJ 3041 Asteroids 二分图最大匹配 - 《挑战程序设计竞赛》例题

    学习网络流中ing...作为初学者练习是不可少的~~~构图方法因为书上很详细了,所以就简单说一说 把光束作为图的顶点,小行星当做连接顶点的边,建图,由于 最小顶点覆盖 等于 二分图最大匹配 ,因此求二 ...

  6. POJ 3041 Asteroids(二分图模板题)

    Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...

  7. POJ 3041 Asteroids 二分图之最大匹配

    题意:在一个网格中有若干个点,每一次可以清除一行或者一列,问最少几次可以将网格中的点全部清除. 思路:这个题是一个入门的最大匹配题(这个好像不是思路..).一般的方式就是将 行 看作集合A,列 看作集 ...

  8. poj 3041 Asteroids(二分图 *【矩阵实现】【最小点覆盖==最大匹配数】)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16379   Accepted: 8930 Descri ...

  9. POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)

    POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...

随机推荐

  1. android开发--sqlite数据库

    一.SQLite简介 Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级 使用 SQL ...

  2. linux网络学习

    ipv4报文处理流程 1.物理层网卡收到报文,产生中断进入中断处理程序:net_interrupt,判断中断是由接收到分组引发后,控制权转移到net_rx: 2.net_rx函数分配一个新的sk_bu ...

  3. SQLSERVER 数值 四舍五入取整 向上取整 向下取整

    [四舍五入取整截取] select round(54.56,0) [向下取整截取] SELECT floor(54.56) [向上取整截取]  SELECT   ceiling(13.15)

  4. 【转】Mac系统中安装homebrew(类似redhat|Centos中的yum;类似Ubuntu中的apt-get)

    Homebrew,Homebrew简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就是mac下的apt-get.yum神器 Homebr ...

  5. 通过浏览器https能够访问SVN,但eclipse SVN,tortoiseSVN始终连接不上SVN的问题解决方案

    为了便于本地代码维护,特意在本地搭建了一个visualSVN服务器用于本地代码管理,但是最近突然出现问题,eclipse上的SVN资源库始终连接不上,提示 "svn: connection ...

  6. Bloom Filter学习

    参考文献: Bloom Filters - the math    http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html    B ...

  7. 15.8.6 AUTO_INCREMENT Handling in InnoDB

    1 传统模式 innodb_autoinc_lock_mode (“traditional” lock mode) 2 连续模式 innodb_autoinc_lock_mode (“consecut ...

  8. Breakpoint is not hit

    新拿到一个Silverlight项目,能够正常运行,但是一旦运行起来,断点处由实心点变成了空心的,并警告:The breakpoint will not currently be hit. No sy ...

  9. python学习笔记4-redis multi watch实现锁库存

    python 关于redis的基本操作网上已经很多了,这里主要介绍点个人觉得有意思的内容1.redis的事务操作以及watch 乐观锁:后面描述2.tornado下异步使用redis的方式       ...

  10. Python os模块之文件操作

    基本概念:C:\\haoguo.txt 路径: C:\\ 文件名: haoguo 后缀名:.txt 1. 文件名与后缀分离 2. 路径与文件分离 3. 获取当前路径 4. 文件名与后缀合并 5. 路径 ...