XTU 二分图和网络流 练习题 B. Uncle Tom's Inherited Land*
B. Uncle Tom's Inherited Land*
64-bit integer IO format: %I64d Java class name: Main
Your uncle Tom wants to sell the inherited land, but local rules now regulate property sales. Your uncle has been informed that, at his great-great-uncle's request, a law has been passed which establishes that property can only be sold in rectangular lots the size of two squares of your uncle's property. Furthermore, ponds are not salable property.
Your uncle asked your help to determine the largest number of properties he could sell (the remaining squares will become recreational parks). 
Input
Output
Sample Input
4 4
6
1 1
1 4
2 2
4 1
4 2
4 4
4 3
4
4 2
3 2
2 2
3 1
0 0
Sample Output
4
(1,2)--(1,3)
(2,1)--(3,1)
(2,3)--(3,3)
(2,4)--(3,4) 3
(1,1)--(2,1)
(1,2)--(1,3)
(2,3)--(3,3) 解题:根据奇偶性建图+最大匹配数+最大匹配数的记录。根据奇偶性建图:在一个平面坐标系中,某个格子的 纵横坐标和 与其相领格子的 纵横坐标和 的绝对值相差1,即相差一个数。由于奇数与偶数相间分布,故只选择纵横坐标和为奇数或者纵横坐标和为偶数的点进行建图(从始至终只能选择其中一种方式),这样保证了是一个二分图。 这题的写法,把原先的匈牙利算法的线段的端点的由的写成了二维的,算法还是那样的。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct{
int x,y;
}link[maxn][maxn];
int n,m;
bool mp[maxn][maxn],vis[maxn][maxn];
bool isIn(int x,int y){
if(x < || x > n || y < || y > m)
return false;
return true;
}
bool dfs(int x,int y){
static const int dir[][] = {{,},{-,},{,},{,-}};
for(int i = ; i < ; i++){
int tx = x+dir[i][];
int ty = y+dir[i][];
if(isIn(tx,ty) && !vis[tx][ty] && !mp[tx][ty]){
vis[tx][ty] = true;
if(link[tx][ty].x == - || dfs(link[tx][ty].x,link[tx][ty].y)){
link[tx][ty].x = x;
link[tx][ty].y = y;
return true;
}
}
}
return false;
}
int main(){
int i,j,u,v,k;
while(scanf("%d%d",&n,&m),n+m){
scanf("%d",&k);
memset(mp,false,sizeof(mp));
while(k--){
scanf("%d%d",&u,&v);
mp[u][v] = ;
}
int ans = ;
memset(link,-,sizeof(link));
for(i = ; i <= n; i++){
for(j = ; j <= m; j++){
memset(vis,false,sizeof(vis));
if(((i+j)&) && !mp[i][j] && dfs(i,j)) ans++;
}
}
printf("%d\n",ans);
for(i = ; i <= n; i++){
for(j = ; j <= m; j++){
if(link[i][j].x != -)
printf("(%d,%d)--(%d,%d)\n",link[i][j].x,link[i][j].y,i,j);
}
}
printf("\n");
}
return ;
}
XTU 二分图和网络流 练习题 B. 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- XTU 二分图和网络流 练习题 J. Drainage Ditches
J. Drainage Ditches Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d Ja ...
- XTU 二分图和网络流 练习题 C. 方格取数(1)
C. 方格取数(1) Time Limit: 5000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d Java class ...
- ZOJ1516 Uncle Tom's Inherited Land(二分图最大匹配)
一个经典的构图:对格子进行黑白染色,黑白的点分别作XY部的点. 这一题的边就是可以出售的单位面积2的土地,边的端点就是这个土地占用的X部和Y部的两个点. 这样就建好二分图,要求最多土地的答案显然是这个 ...
随机推荐
- GDI双缓冲绘图
一.简介 在进行复杂图形绘制时,若直接在屏幕DC上进行绘制,则会出现明显的闪烁.闪烁产生的原因是当绘制的图形较为 复杂时,图形绘制过程中就被刷新到屏幕上,导致结果断断续续地显示出来.双缓冲绘图的原理是 ...
- Eclipse 运行内存不足情况
在debug或者run 时 在VM arguments 处添加 -Xms512m -Xmx512m
- (025)[系统故障]XP下禁止将串口设备识别成鼠标(转)
很多人都遇到过这种问题:Windows XP启动时将一台连续发送数据的串口设备识别成串口鼠标,自动安装了串口鼠标驱动,而设备因此无法正常工作,而光标则无规律地到处跑.对此问题,Internet上的方法 ...
- CCS3超长文字显示省略号的方法
需求:当文本长度溢出包含元素时以省略号结尾 CSS3实现方法: #MyDIV{overflow:hidden;text-overflow:ellipsis;} 示例:<!DOCTYPE html ...
- 初探ABP--记一些常见的开发问题
1.Update-Database : 无法将“Update-Database”项识别为 cmdlet.函数.脚本文件或可运行程序的名称.请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次. ...
- js递归和数组去重(简单便捷的用法)
1.递归例子<script type="text/javascript"> function test(num) { if(num < 0) { return; ...
- 微信小程序开发系列七:微信小程序的页面跳转
微信小程序开发系列教程 微信小程序开发系列一:微信小程序的申请和开发环境的搭建 微信小程序开发系列二:微信小程序的视图设计 微信小程序开发系列三:微信小程序的调试方法 微信小程序开发系列四:微信小程序 ...
- Devops 技术图谱
- 解决margin塌陷问题
父元素添加: border: 1px solid transparent; 或者 over-flow:hidden;
- Session/EntityManager is closed
Hinbernate操作数据库必须要开启事务, 但是在添加事务的时候遇到这个问题也是郁闷, 说Session被关闭了, 而这个Session又是必须的. 关键是我并没有关闭, 也找不到是哪里被关闭了的 ...