POJ2226:Muddy Fields(二分图)
来源:互联网 发布:adobe系列软件介绍 编辑:程序博客网 时间:2024/04/29 07:09
Muddy Fields
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10832 Accepted: 4025
Description
Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R <= 50, 1 <= C <= 50). While good for the grass, the rain makes some patches of bare earth quite muddy. The cows, being meticulous grazers, don't want to get their hooves dirty while they eat.
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.
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
* Line 1: Two space-separated integers: R and C
* 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.
* 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
* Line 1: A single integer representing the number of boards FJ needs.
Sample Input
4 4*.*..******...*.
Sample Output
4
Hint
OUTPUT DETAILS:
Boards 1, 2, 3 and 4 are placed as follows:
1.2.
.333
444.
..2.
Board 2 overlaps boards 3 and 4.
Boards 1, 2, 3 and 4 are placed as follows:
1.2.
.333
444.
..2.
Board 2 overlaps boards 3 and 4.
Source
USACO 2005 January Gold
题意:N*M的地图,*是泥地,.是草地,有无限块宽为1的无限长的木板,需要把泥地盖住,而不能盖住草地,问所需木板的最少数目。
思路:对于每个*,横纵坐标建边,这就是一个二分图,即求最小点覆盖数=最大匹配数,但是这里要求不能盖住草地,所以同一行(或列)非连续的泥地,都视为不同行(或列),这样处理下再跑最大匹配即可。
# include <iostream># include <cstdio># include <cstring># include <vector>using namespace std;const int N = 53;int l[2600], vis[2600];char s[N][N];int p[N][N], q[N][N];vector<int>v[2600];int cnt = 0, cnt2 = 0;int dfs(int u){ for(int i=0; i<v[u].size(); ++i) { int j = v[u][i]; if(!vis[j]) { vis[j] = 1; if(l[j]==-1 || dfs(l[j])) { l[j] = u; return 1; } } } return 0;}int main(){ int n, m; while(~scanf("%d%d",&n,&m)) { cnt = cnt2 = 0; memset(l, -1, sizeof(l)); for(int i=1; i<=n; ++i) scanf("%s",s[i]+1); for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) if(s[i][j] == '*') { if(j-1>0&&s[i][j-1]=='*') q[i][j] = q[i][j-1]; else q[i][j] = ++cnt2; if(i-1>0&&s[i-1][j]=='*') p[i][j] = p[i-1][j]; else p[i][j] = ++cnt; } for(int i=0; i<=cnt2; ++i) v[i].clear(); for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) if(s[i][j] == '*') v[q[i][j]].push_back(p[i][j]); int ans = 0; for(int i=1; i<=cnt2; ++i) { memset(vis, 0, sizeof(vis)); if(dfs(i)) ++ans; } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- POJ2226:Muddy Fields(二分图)
- 【poj2226】Muddy Fields 二分图
- POJ2226 Muddy Fields【二分图最小点覆盖】
- POJ2226 Muddy Fields 二分图求最小覆盖点
- POJ2226 Muddy Fields
- poj2226 - Muddy Fields
- POJ2226 Muddy Fields
- poj2226 Muddy Fields
- poj2226 Muddy Fields
- poj2226 Muddy Fields
- POJ2226 Muddy Fields
- POJ2226 Muddy Fields
- poj2226 muddy fields
- 【poj2226】 Muddy Fields
- poj 2226 Muddy Fields(二分图)
- poj2226——Muddy Fields
- 最小点覆盖 poj2226 Muddy Fields
- poj 2226 Muddy Fields(二分图匹配)
- tomcat容器下 http 请求参数中特殊字符(+、&、%)的问题
- Android 教你打造炫酷的ViewPagerIndicator 不仅仅是高仿MIUI
- c++各类运算优先级
- pandas入门——多重索引
- 容器类的组织结构图
- POJ2226:Muddy Fields(二分图)
- 你未必知道 Linux操作系统进程间通信
- nginx代理udp
- React 之 setState
- Android Xfermode 实战 实现圆形、圆角图片
- kiki's game(hdu2147)
- POJ1655-树的重心&树形dp-Balancing Act
- java操作pdf>>>pdfBox使用体验
- 1043 幸运号码 数位dp