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升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
随机推荐
- 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)
转载自 http://blog.csdn.net/william001zs/article/details/6213485 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...
- bzoj2878
又是环套树dp,这次不是我擅长的类型 首先考虑树上的暴力,肯定是穷举起点然后以起点为根dp 我们用g[i]表示以点i为期望走的路径总长,答案就是1/n*Σ(g[i]/d[i]) (d[i]表示点度数) ...
- poj3468,poj2528
其实这两题都是基础的线段树,但对于我这个线段树的初学者来说,总结一下还是很有用的: poj3468显然是线段树区间求和,区间更改的问题,而poj2528是对区间染色,问有多少种颜色的问题: 线段树的建 ...
- ASP.NET MVC 学习2、从Controller传递数据到View
参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-view 一,Control ...
- onkeypress与onkeydown及 oncopy和onpaste 事件区别详细说明
onkeypress与onkeydown 具体区别: 1. 一个放开一个没有放开,onkeydown 先于 onkeypress 发生. 2.onkeypress 无法系统按钮. 2.onkeydow ...
- Can't dispatch DDM chunk 52454151: no handler defined
[2010-07-12 10:10:06 - Hello Google Android]ActivityManager: DDM dispatch reg wait timeout [2010-07- ...
- jquery 滚动条插件 jquery.nanoscroller.js
$(".listcontent .nano").nanoScroller(); $(".chatcontent .nano").nanoScroller({ ...
- JS全局变量VAR和THIS
(注意)JS全局变量VAR和THIS 很多人都觉得在javascript声明一个变量,加var和不加var没有什么区别,实际上是一个错误的观点,如果在函数外面,也就是说在window区域加不加var确 ...
- django --------------------- [必要操作]
基本models 命令: python manage.py validate (验证模型有效性, 记得配置 settings.py - INSTALLED_APPS) python manage.py ...
- Swift入门篇-基本类型(1)
博主语文一直都不好(如有什么错别字,请您在下评论)望您谅解,没有上过什么学的 今天遇到了一个很烦的事情是,早上10点钟打开电脑,一直都进入系统(我的系统 mac OS X Yosemite 10.1 ...