HDU1507 Uncle Tom's Inherited Land*
题目是跟 zoj1516是一样的,但多了匹配后的输出
详解zoj1516可见http://www.cnblogs.com/CSU3901130321/p/4228057.html
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; const int maxn = ;
int n , m , k;
int g[maxn][maxn] , cx[maxn] , cy[maxn] , visy[maxn] , nx , ny;
bool col[][];//判断是否为鱼塘 struct Point{
int x , y;
Point(int x= , int y=):x(x),y(y){}
}; Point px[maxn] , py[maxn]; bool ok(Point p1 , Point p2)
{
if((p1.x == p2.x && abs(p1.y - p2.y) == ) || (p1.y == p2.y && abs(p1.x - p2.x) == ))
return true;
return false;
} void build_graph()
{
memset(g , , sizeof(g));
for(int i= ; i<=nx ; i++){
for(int j= ; j<=ny ; j++){
if(ok(px[i] , py[j]))
g[i][j] = ;
}
}
} int dfs(int u)
{
for(int v = ; v<=ny ; v++)
if(g[u][v] && !visy[v]){
visy[v] = ;
if(cy[v] == - || dfs(cy[v])){
cx[u] = v;
cy[v] = u;
return ;
}
}
return ;
} int MaxMatch()
{
memset(cx , - , sizeof(cx));
memset(cy , - , sizeof(cy));
int ans = ;
for(int i= ; i<=nx ; i++){
if(cx[i] == -){
memset(visy , , sizeof(visy));
ans += dfs(i);
}
}
return ans;
} int main()
{
// freopen("a.in" , "r" ,stdin);
while(scanf("%d%d" , &n , &m) , n)
{
scanf("%d" , &k);
int x , y;
memset(col , , sizeof(col));
while(k--){
scanf("%d%d" , &x , &y);
col[x][y] = ;
}
nx = , ny = ;
for(int i= ; i<=n ; i++)
for(int j= ; j<=m ; j++)
if(!col[i][j]){
if((i+j)&) py[++ny] = Point(i,j);
else px[++nx] = Point(i,j);
}
//构造二分图
build_graph();
printf("%d\n" , MaxMatch());
for(int i= ; i<=nx ; i++){
if(cx[i] != -)
printf("(%d,%d)--(%d,%d)\n",px[i].x , px[i].y , py[cx[i]].x , py[cx[i]].y);
}
}
return ;
}
HDU1507 Uncle Tom's Inherited Land*的更多相关文章
- 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 ...
- HDU1507 Uncle Tom's Inherited Land* 二分图匹配 匈牙利算法 黑白染色
原文链接http://www.cnblogs.com/zhouzhendong/p/8254062.html 题目传送门 - HDU1507 题意概括 有一个n*m的棋盘,有些点是废的. 现在让你用1 ...
- hdu1507 Uncle Tom's Inherited Land* 二分匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...
- 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 ...
- Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Uncle Tom's Inherited Land*
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 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 ...
- XTU 二分图和网络流 练习题 B. Uncle Tom's Inherited Land*
B. Uncle Tom's Inherited Land* Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I ...
- HDU——T 1507 Uncle Tom's Inherited Land*
http://acm.hdu.edu.cn/showproblem.php?pid=1507 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
随机推荐
- J201700526-hm
プレーンテキスト 纯文本 きも 肝 リレーショナル 亲属的,相关的,有关的; ギャップ 缺口; 间隔; 分歧;
- bzoj 3231: [Sdoi2008]递归数列【矩阵乘法】
今天真是莫名石乐志 一眼矩阵乘法,但是这个矩阵的建立还是挺有意思的,就是把sum再开一列,建成大概这样 然后记!得!开!long!long!! #include<iostream> #in ...
- P4128 [SHOI2006]有色图
传送门 数学渣渣看题解看得想死Ծ‸Ծ 首先发现这玩意儿看着很像polya定理 \[L=\frac{1}{|G|}\sum_{i\in G}m^{w(i)}\] 然而polya定理只能用来求点的置换,边 ...
- 题解报告:hdu 1312 Red and Black(简单dfs)
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- Redis基础---5个基本数据结构(比较性记忆)
“ Redis是一个内存数据库,只用硬盘来进行持久化. Mongodb是半内存数据库 Mysql是硬盘数据库 ” 1. Redis启动 安装好了之后.运行redis-3.2.8/src/下的redis ...
- 树莓派 关闭屏保 / RaspberryPi turn off ScreenSaver / RaspberryPi disable screen off
安装xscreensaver并配置 见:https://www.raspberrypi.org/forums/viewtopic.php?t=57552
- System.AppDomain类详解(一)
AppDomain是CLR(Common Language Runtime:公共语言运行库),它可以加载Assembly.创建对象以及执行程序. AppDomain是CLR实现代码隔离的基本机制. 每 ...
- [ USACO 2017 FEB ] Why Did the Cow Cross the Road III (Gold)
\(\\\) \(Description\) 给定长度为\(2N\)的序列,\(1\text ~N\)各出现过\(2\)次,\(i\)第一次出现位置记为\(a_i\),第二次记为\(b_i\),求满足 ...
- cocos2d-x android 环境部署
1.下载jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.下载 and ...
- 关于微信小程序:scroll-view,backgroundTextStyle
踩过的坑mark下 1.滚动列表最好不要用scroll-view组件,这个组件有不少问题,比如触顶操作触发了,会连续好几次执行触发函数,得用一个开关变量和定时器配合来控制,一般情况下view组件就够用 ...