题解:

二分图最大匹配

建边和第一题差不多

每两个相邻的建边

然后输出方案

代码:

#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. iOS 绘制一个表盘时钟,秒针效果可以“扫秒/游走”

    最近自己 也尝试写了一个表盘时钟,初衷源于等车时候一个老奶奶问时间,我打开手机,时间数字对我来说相对敏感,但是老奶奶是看不清的,我想识别 还是看表盘 老远 看时针分针角度就可以识别当前时间. 于是我想 ...

  2. 使用tar解压文件报归档中找不到

    1.今天使用tar命令解压jdk安装包时,报如下错误.tar -zxvf jdk-8u181-linux-x64.tar.gz /usr/local/java/ 2.后来查了一下,因为我解压当前的文件 ...

  3. [2011-3-9 12:59 ]As3.0中的位图(Bitmap/BitmapData)用法

    1.位图使用(模糊)滤镜 //创建一个矩形区域的BitmapData var bmd:BitmapData = new BitmapData(80, 30, false, 0xefefef); //画 ...

  4. USB Transfer and Packet Sizes

    https://msdn.microsoft.com/en-us/library/ff538112.aspx http://blog.csdn.net/chenyujing1234/article/d ...

  5. 解读:Hadoop Archive

    hdfs并不擅长存储小文件,因为每个文件最少一个block,每个block的元数据都会在NameNode中占用150byte内存.如果存储大量的小文件,它们会吃掉NameNode节点的大量内存.MR案 ...

  6. JSON 中JsonConfig的使用(转)

    我们通常对一个Json串和Java对象进行互转时,经常会有选择性的过滤掉一些属性值,而json-lib包中的JsonConfig为我们提供了这种 功能,具体实现方法有以下几种.(1)建立JsonCon ...

  7. 安装配置mariadb-10.1.19

    本文参考:http://chenzehe.iteye.com/blog/1266260  感谢原作者的分享! 首先安装/更新一些编译时会用到的基础包 [root@localhost local]# y ...

  8. VirtualBox安装RedHat7

    软件准备 VirtualBox-5.2.8-121009-Win.exe rhel-server-7.4-x86_64-dvd.iso 安装环境 win10 安装步骤: 1.先在win10系统中安装V ...

  9. PRcurve

    https://blog.csdn.net/qq_33350808/article/details/83178002 问题:删掉pkl

  10. Mybatis中传参包There is no getter for property named 'XXX' in 'class java.lang.String'

    Mybatis中传参包There is no getter for property named 'XXX' in 'class java.lang.String' 一.发现问题 <select ...