题解:

二分图最大匹配

建边和第一题差不多

每两个相邻的建边

然后输出方案

代码:

#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=;
int vis[N],a[N][N],ans[N],map[N][N],g[N];
int k,n,m,sum,num;
struct node{int x,y;}p[N*N];
int dfs(int x)
{
for (int i=;i<num;i++)
if (!vis[i]&&a[x][i])
{
vis[i]=;
if (ans[i]==-||dfs(ans[i]))
{
ans[i]=x;
return ;
}
}
return ;
}
void match()
{
sum=;
memset(ans,-,sizeof(ans));
for(int i=;i<num;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)) sum++;
}
}
int main()
{
while (scanf("%d%d",&n,&m))
{
if (!n&&!m) break;
int u,v;
memset(a,,sizeof(a));
memset(map,,sizeof(map));
scanf("%d",&k);
while (k--)
{
scanf("%d%d",&u,&v);
map[u][v]=;
}
num=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (map[i][j]==)
{
p[num].x=i;
p[num++].y=j;
}
for (int l=;l<num;l++)
for (int j=l+;j<num;j++)
if ((abs(p[l].x-p[j].x)==&&p[l].y==p[j].y)
||(abs(p[l].y-p[j].y)==&&p[l].x==p[j].x))
if ((p[l].x+p[l].y)%==)a[j][l]=;else a[l][j]=;
match();
printf("%d\n",sum);
for (int i=;i<num;i++)
if (ans[i]!=-)
printf("(%d,%d)--(%d,%d)\n",p[i].x,p[i].y,p[ans[i]].x,p[ans[i]].y);
printf("\n");
}
return ;
}

hdu1507的更多相关文章

  1. hdu1507二分匹配

    1 //hdu1507 挺不错的题 #include<stdio.h> #include<string.h> #define INF 99999999 struct node ...

  2. HDU1507 Uncle Tom's Inherited Land* 二分图匹配 匈牙利算法 黑白染色

    原文链接http://www.cnblogs.com/zhouzhendong/p/8254062.html 题目传送门 - HDU1507 题意概括 有一个n*m的棋盘,有些点是废的. 现在让你用1 ...

  3. 「日常训练」Uncle Tom's Inherited Land*(HDU-1507)

    题意与分析 题意是这样的:给你一个\(N\times M\)的图,其中有一些点不能放置\(1\times 2\)大小的矩形,矩形可以横着放可以竖着放,问剩下的格子中,最多能够放多少个矩形. 注意到是\ ...

  4. hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  5. hdu1507最大匹配

    题意:给出n*m的矩阵方块,某些方块是ponds,这些方块不能出售,然后能出售的是1*2的方块 要求求出有多少块1*2的方块能够出售,并输出这些方块的坐标(specia judge) 关键是怎么建出二 ...

  6. hdu1507 Uncle Tom's Inherited Land* 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...

  7. HDU1507二分图

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  8. hdu1507——Uncle Tom&#39;s Inherited Land*

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  9. HDU1507 Uncle Tom's Inherited Land*

    题目是跟 zoj1516是一样的,但多了匹配后的输出 详解zoj1516可见http://www.cnblogs.com/CSU3901130321/p/4228057.html #include & ...

随机推荐

  1. ONVIF学习-ONVIF开发框架搭建(C++)

    第一步.下载gsoap 从gsoap官网(http://www.genivia.com/products.html#notice)下载最新版gsoap(博主用的是gsoap_2.8.45).gsoap ...

  2. 【Python】高阶函数

    filter def is_palindrome(n): L = str(n) i = 0 j = len(L) - 1 while i != j: if L[i] != L[j]: return F ...

  3. RabbitMQ学习之(二)_Centos6下安装RabbitMQ及管理配置

    首先yum方式安装依赖包 yum install ncurses-devel unixODBC unixODBC-devel 安装Erlang语言环境 wget http://erlang.org/d ...

  4. 20144303《Java程序设计》第10周学习总结

    20144303<Java程序设计>第10周学习总结 教材学习内容总结 网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能,但是很多的初学者却因为很长一段时间无法进入网络编程 ...

  5. jsp判断以某个字母开头

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ tag ...

  6. Excel导出失败的提示

    未处理System.InvalidCastException HResult=-2147467262 Message=无法将类型为“Microsoft.Office.Interop.Excel.App ...

  7. LeetCode——Coin Change

    Question You are given coins of different denominations and a total amount of money amount. Write a ...

  8. sscanf输入总结

    2017-08-21 15:09:47 writer:pprp sscanf很好用的,一般配合gets()来使用 /* theme: usage of sscanf writer:pprp date: ...

  9. word2vector 使用方法 计算语义相似度

    参考:http://techblog.youdao.com/?p=915#LinkTarget_699word2vector是一个把词转换成词向量的一个程序,能够把词映射到K维向量空间,甚至词与词之间 ...

  10. cocos2d-x入门三 分层设计框架

    helloworld就是一个完整的框架,大致分为四个层次如下: 导演-------场景------图层-----精灵 Director-----Scene----Layer----Sprite 导演类 ...