poj 2226 Muddy Fields(最小覆盖点+构图)
http://poj.org/problem?id=2226
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 9022 | Accepted: 3348 |
Description
To prevent those muddy hooves, Farmer John will place a number of wooden boards over the muddy parts of the cows' field. Each of the boards is 1 unit wide, and can be any length long. Each board must be aligned parallel to one of the sides of the field.
Farmer John wishes to minimize the number of boards needed to cover the muddy spots, some of which might require more than one board to cover. The boards may not cover any grass and deprive the cows of grazing area but they can overlap each other.
Compute the minimum number of boards FJ requires to cover all the mud in the field.
Input
* Lines 2..R+1: Each line contains a string of C characters, with '*' representing a muddy patch, and '.' representing a grassy patch. No spaces are present.
Output
Sample Input
4 4
*.*.
.***
***.
..*.
Sample Output
4
Hint
Boards 1, 2, 3 and 4 are placed as follows: 1.2. .333 444. ..2. Board 2 overlaps boards 3 and 4.
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define N 1100 int G[N][N], vis[N], used[N];
char maps[N][N];
int m, n, x, y; bool Find(int u)
{
int i;
for(i = ; i <= y ; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} void Build()//构图
{
int i, j, a[N][N] , b[N][N];
x = y = ;
memset(a, , sizeof(a));
memset(b, , sizeof(b));
for(i = ; i <= m ; i++)
{
for(j = ; j <= n ; j++)
{
if(maps[i][j] == '*')
{
if(maps[i][j - ] == '*')
a[i][j] = a[i][j - ];
else
a[i][j] = ++x;
}
}
}//木板横着放
for(i = ; i <= m ; i++)
{
for(j = ; j <= n ; j++)
{
if(maps[i][j] == '*')
{
if(maps[i - ][j] == '*')
b[i][j] = b[i - ][j];
else
b[i][j] = ++y;
G[a[i][j]][b[i][j]] = ;
}
}
}//木板竖着放
} int main()
{
int i, j, ans;
while(~scanf("%d%d", &m, &n))
{
ans = ;
memset(G, , sizeof(G));
for(i = ; i <= m ; i++)
{
getchar();
for(j = ; j <= n ; j++)
{
scanf("%c", &maps[i][j]);
}
}
Build();
memset(used, , sizeof(used));
for(i = ; i <= x ; i++)//X集合中的点与Y集合中的点找最大匹配
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", ans);
}
return ;
}
poj 2226 Muddy Fields(最小覆盖点+构图)的更多相关文章
- POJ 2226 Muddy Fields(最小顶点覆盖)
POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...
- poj 2226 Muddy Fields (转化成二分图的最小覆盖)
http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2226 Muddy Fields (二分匹配)
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7340 Accepted: 2715 Desc ...
- [POJ] 2226 Muddy Fields(二分图最小点覆盖)
题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...
- poj 2226 Muddy Fields(最小点覆盖+巧妙构图)
Description Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= ...
- POJ 2226 Muddy Fields(二分匹配 巧妙的建图)
Description Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R ...
- POJ 2226 Muddy Fields (二分图匹配)
[题目链接] http://poj.org/problem?id=2226 [题目大意] 给出一张图,上面有泥和草地,有泥的地方需要用1*k的木板覆盖, 有草地的地方不希望被覆盖,问在此条件下需要的最 ...
- poj 2226 Muddy Fields(合理建图+二分匹配)
/* 题意:用木板盖住泥泞的地方,不能盖住草.木板任意长!可以重叠覆盖! '*'表示泥泞的地方,'.'表示草! 思路: 首先让我们回忆一下HDU 2119 Matrix这一道题,一个矩阵中只有0, 1 ...
- POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
随机推荐
- CFF前端沙龙总结
一. -OOCSS + Sass ——大漠 1. OOCSS 结构<=>皮肤 分离 容器<=>内容 分离 2. Sass 工具.处理器 SCSS(CSS风格)<=> ...
- ireport制作小技巧
ireport制作小技巧 首先ireport中大小写问题: 1.parameter中如果小写,引用也小写 2.$F{},一般都大写 3.子报表中引用父报表中查询出来的值时,只需要小写即可,即在子报表的 ...
- Android中使用广播机制退出多个Activity
谷歌百度一下,Android中退出多个Activity的方法,大家讨论的很多. 在实习的时候,看到公司的项目退出多个Activity,是采用LinkedList方法,毕业设计的时候,也参照了那种方法. ...
- System.exit(0)
表示程序正常退出 System.exit(status) 当status非0时,表示程序为非正常退出. status=0, 关闭当前正在运行的虚拟机. 求质因数分解的程序如下: 两种算法: 一种是用S ...
- Drupal 7.31版本爆严重SQL注入漏洞
今早有国外安全研究人员在Twitter上曝出了Drupal 7.31版本的最新SQL注入漏洞,并给出了利用测试的EXP代码. 在本地搭建Drupal7.31的环境,经过测试,发现该利用代码可成功执行并 ...
- 设置Android默认锁定屏幕旋转
/********************************************************************************** * 设置Android默认锁定屏 ...
- .Net中的各种序列化
我们知道将对象的状态保持在存储媒体中,以便可以在以后重新创建精确的副本这正是数据持久化所要做的.而且,不同应用程序之间的通讯需要相互传输数据.那么序列化和反序列化正是为此而生. 序列化和反序列化 所谓 ...
- Zend Framework 入门(3)—错误处理
undefined 说明脚本中一些对象没有设定 你应在在使用该对象前进行判断 例如: if(typeof(aobject) == "undefined"){ //错误处理 }
- MBR与GRUB简介
在坛子里找到一篇关于grub和mbr工作原理的文章,以前一直都是一头雾水,今天转这文章学习下..哈.. 能正常工作的grub应该包 括一下文件:stage1.stage2.*stage1_5.menu ...
- .NET Remoting
.NET Remoting .NET Remoting是微软早期的分布式通信技术,虽然微软后来通过WCF通用基础通信框架整合掉了,但是通过回顾学习Remoting,反过来学习理解WCF也是很有帮助 ...