ZOJ 1516 Uncle Tom's Inherited Land
题目大意:
除去那些作为荷塘的土地块,将剩余的土地希望每次将两块相邻的地一起卖出,最多能卖出多少种这样的由相邻土地
合成的长方形土地块
很明显的二分图问题,但是要考虑如何建模
一个长方形土地总是由相邻的两块地组成,那么我们就将相邻的两块地一块放在X集合,一块放在Y集合
所有放在X集合中的土地互不影响(也就是任意两个在X中的土地不形成长方形)
那么我们可以看作土地上
0101010
1010101
0101010
1010101
比如这样标注的,那么0所对应的空地就放入集合X,并不断添加一个X的标号
同理,1所在空地添入集合Y,并不断添加一个Y的标号
剩下的就是用匈牙利算法求X到Y的最大匹配了
- #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());
- }
- return ;
- }
ZOJ 1516 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*(二分图匹配)
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 ...
- ZOJ 1516 Uncle Tom's Inherited Land(二分匹配 最大匹配 匈牙利啊)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=516 Your old uncle Tom inherited a p ...
- 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 ...
- ZOJ1516 Uncle Tom's Inherited Land(二分图最大匹配)
一个经典的构图:对格子进行黑白染色,黑白的点分别作XY部的点. 这一题的边就是可以出售的单位面积2的土地,边的端点就是这个土地占用的X部和Y部的两个点. 这样就建好二分图,要求最多土地的答案显然是这个 ...
随机推荐
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...
- Java并发编程系列之CyclicBarrier详解
简介 jdk原文 A synchronization aid that allows a set of threads to all wait for each other to reach a co ...
- c#自定义ORM框架---(泛型&反射&实体类扩展属性<附带通用增、删、查、改>)
该教材主要是运用到泛型.反射和实体类扩展属性 步骤一.建立扩展属性类 实体类扩展属性要继承Attribute基类完成 [AttributeUsage(AttributeTargets.Property ...
- 发生在升级OS X Yosemite后:修复各种开发环境
本博文最初发布于我的个人博客<Jerry的乐园> 终于还是忍不住升级了,促使我升级的原动力居然是Alfred的Yosemite theme居然比初始theme好看很多!在升级前就预想到我的 ...
- SQL编程语句
视图 视图就是我们查询出来的虚拟表创建视图:create view 视图名 as SQL查询语句,分组,排序,in 等都不能写视图的用法: select * from 视图名 SQL编程 定义变量:d ...
- myBatis逆向生成及使用
引入数据库驱动 <!-- mybatis逆向生成包 --><dependency> <groupId>org.mybatis.generator</group ...
- (二)Mybatis总结之通过Dao层与数据交互
Mybatis概述 定义: Mybatis是一个支持普通sql查询,存储过程和高级映射的优秀持久层框架. Mybatis是(半自动的)跟数据库打交道的orm(object relationship m ...
- post登录资料备份
# coding=utf-8 import urllib import hashlib import http.client import http.cookiejar import http.coo ...
- PSP辅助软件开发计划
PSP辅助软件开发计划 作者: 日期:2013年11月14号 1开发目的 鉴于软件开发过程中,程序员往往无法在规定时间内完成任务,而且无法给出拖延的时间从而造成项目进度计划不准确.开发此软件帮助程序员 ...
- POJ_1088_(dp)(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 95792 Accepted: 36322 Description ...