1 //hdu1507 挺不错的题
#include<stdio.h>
#include<string.h>
#define INF 99999999
struct node
{
int x;
int y;
}rem[];
struct Node
{
int v;
int next;
}edge[];
int n,m,num,vis[],match[],map[][],mmark[],index,pre[];
void add(int x,int y)
{
edge[index].v=y;
edge[index].next=pre[x];
pre[x]=index++;
}
void build(int x,int y,int a,int b)
{
int i,j;
if(a<=||a>n||b<=||b>m||map[a][b]==)
return ;
else add(map[x][y],map[a][b]);
}
void test(int x,int y)
{
build(x,y,x-,y);
build(x,y,x+,y);
build(x,y,x,y-);
build(x,y,x,y+);
}
void makemap()
{
int i,j;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(map[i][j]==)
continue;
test(i,j);
}
}
int dfs(int u)
{
int i,j;
for(i=pre[u];i!=-;i=edge[i].next)
{
int j=edge[i].v;
if(!vis[j])
{
vis[j]=;
if(match[j]==-||dfs(match[j]))
{
match[j]=u;
return ;
}
}
}
return ;
}
int main()
{
int i,j,k;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(!n&&!m)break;
scanf("%d",&k);
memset(mmark,,sizeof(mmark));
for(i=;i<=n;i++)
for(j=;j<=m;j++)
map[i][j]=INF; for(i=;i<k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
map[x][y]=;
} num=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(map[i][j])
{
map[i][j]=num;
rem[num].x=i;
rem[num++].y=j;
}
}
/*for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
printf("%d ",map[i][j]);
printf("\n");
}*/
index=;
memset(pre,-,sizeof(pre));
makemap();
/*for(i=1;i<num;i++)
{
for(j=1;j<num;j++)
{
printf("%d ",g[i][j]);
}
printf("\n");
}*/
memset(match,-,sizeof(match));
int ans=;
for(i=;i<num;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
int mark[];
memset(mark,,sizeof(mark));
printf("%d\n",ans/);
for(i=;i<num;i++)
{
if(!mark[i]&&!mark[match[i]]&&match[i]!=-)
{
printf("(%d,%d)--(%d,%d)\n",rem[i].x,rem[i].y,rem[match[i]].x,rem[match[i]].y);
mark[i]=;mark[match[i]]=;
}
}
printf("\n");
}
} /* 3 3
4
2 3
1 3
3 2
1 2
4 5
6
1 2
1 3
3 5
3 4
4 2
2 5 */

hdu1507二分匹配的更多相关文章

  1. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  2. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  3. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  4. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  5. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  6. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  7. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  8. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

  9. UVA5874 Social Holidaying 二分匹配

    二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...

随机推荐

  1. java常用方法总结

    最近打算换工作,还是需要补一下面试的基础知识,写了一些面试中可能会用到的常用算法.方法,以便复习 //99乘法表 /** * 1*1 * 1*1 1*2 * 1*1 1*2 1*3 * …… * */ ...

  2. Golang tool:include spider library,image library and some other db library such as mysql,redis,mogodb,hbase,cassandra

    一.Go_tool This is a tool library for Golang.Dont't worry about not understant it! All comment writes ...

  3. mysql 存储过程,以及mybatis如何调用

    说道存储过程,很多人都知道,但是真正用的人其实很少,但是在某些必要的场景,是必须使用的,虽然可以使用java代码解决,但是效率性能远不及存储过程 曾经在sqlserver 以及pgadmin上用过,m ...

  4. 第22章 DLL注入和API拦截(2)

    22.4 使用远程线程来注入DLL 22.4.1 概述 (1)远程线程注入是指一个进程在另一个进程中创建线程,然后载入我们编写的DLL,并执行该DLL代码的技术.其基本思路是通过CreateRemot ...

  5. Linux搭建python环境中cx_Oracle模块安装遇到的问题与解决方法

    安装或使用cx_Oracle时,需要用到Oracel的链接库,如libclntsh.so.11.1,否则会有各种各样的错误信息. 安装Oracle Instant Client就可得到这个链接库,避免 ...

  6. IT技术博客收藏

    1. coolshell.cn 特点: 每篇都是精品 2. 云风 特点: 3. 阮一峰的博客 特点:高精深 3. offbye涛声依旧-全端技术博客 特点: android的开发技术比较多,非常值得一 ...

  7. 上传图片shell绕过过滤的方法

    一般网站图片上传功能都对文件进行过滤,防止webshelll写入.但不同的程序对过滤也不一样,如何突破过滤继续上传? 本文总结了七种方法,可以突破! .文件头+GIF89a法.(php)//这个很好理 ...

  8. js常用宽高属性

    document.body.clientWidth //body对象的宽度 document.body.clientHeight //body对象的高度 document.documentElemen ...

  9. 第三章 Models模块属性详解

    摘自:http://www.cnblogs.com/xdotnet/archive/2012/03/07/aspnet_mvc40_validate.html 了解了这些就可以对MVC进一步认识,相信 ...

  10. 【C#】WM 消息大全

    消息名 消息值 说明 WM_CREATE 0x0001 应用程序创建一个窗口 WM_DESTROY 0x0002 一个窗口被销毁 WM_MOVE 0x0003 移动一个窗口 WM_SIZE 0x000 ...