POJ 题目2226 Muddy Fields(最小点覆盖)
2015-02-14 00:15
337 查看
Muddy Fields
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.
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.
Output
* Line 1: A single integer representing the number of boards FJ needs.
Sample Input
Sample Output
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.
Source
USACO 2005 January Gold
ac代码
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8581 | Accepted: 3164 |
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.
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.
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.
Source
USACO 2005 January Gold
ac代码
#include<stdio.h> #include<string.h> int x[2200][2200],y[2200][2200],n1,n2,ans[2200][2200],v[2200],link[2200]; char map[220][220]; int dfs(int u) { int i; for(i=1;i<=n2;i++) { if(!v[i]&&ans[u][i]) { v[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=u; return 1; } } } return 0; } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int i,j,sum=0; for(i=1;i<=n;i++) { scanf("%s",&map[i][0]+1); } n1=n2=1; memset(ans,0,sizeof(ans)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(map[i][j]=='*') { x[i][j]=n1; // y[i][j]=n2; // ans[x[i][j]][y[i][j]]=1; } if(map[i][j]=='*'&&map[i][j+1]!='*') n1++; //if(map[i][j]=='*'&&map[i+1][j]!='*') // n2++; } } for(j=1;j<=m;j++) { for(i=1;i<=n;i++) { if(map[i][j]=='*') { // x[i][j]=n1; y[i][j]=n2; // ans[x[i][j]][y[i][j]]=1; } //if(map[i][j]=='*'&&map[i][j+1]!='*') // n1++; if(map[i][j]=='*'&&map[i+1][j]!='*') n2++; } } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(map[i][j]=='*') ans[x[i][j]][y[i][j]]=1; } } memset(link,-1,sizeof(link)); for(i=1;i<=n1;i++) { memset(v,0,sizeof(v)); if(dfs(i)) sum++; } printf("%d\n",sum); } }
相关文章推荐
- POJ 2226 Muddy Fields(最小顶点覆盖)
- POJ 2226 Muddy Fields【二分图最小点覆盖】
- poj 2226 Muddy Fields(最小点覆盖)
- poj 2226 Muddy Fields(最小点集覆盖)
- POJ - 2226 Muddy Fields 二分图 最小点覆盖
- poj 2226 Muddy Fields 最小顶点覆盖
- POJ 2226 Muddy Fields(最小点覆盖)
- POJ 2226 Muddy Fields (最小点覆盖)
- [POJ] 2226 Muddy Fields(二分图最小点覆盖)
- poj 2226 Muddy Fields(最小点覆盖+巧妙构图)
- POJ 2226 Muddy Fields(最小点覆盖)
- POJ-2226-Muddy Fields-二分图-最小点覆盖
- poj 2226 Muddy Fields(二分图——最小点覆盖)
- poj 2226 Muddy Fields(二分图最小点覆盖)
- poj 2226 Muddy Fields 最小点覆盖
- POJ 2226-Muddy Fields(二分图_最小点覆盖+神建图orz)
- poj 2226 Muddy Fields (转化成二分图的最小覆盖)
- POJ-2226 Muddy Fields 最小点集覆盖
- POJ 2226 Muddy Fields 匈牙利算法/最小点覆盖
- POJ 2226 Muddy Fields(匈牙利算法—最小点覆盖)