博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2226 Muddy Fields
阅读量:6708 次
发布时间:2019-06-25

本文共 2685 字,大约阅读时间需要 8 分钟。

 

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10149   Accepted: 3783

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

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

 

将连续的一段横/纵条算作同一个,若横纵条相交则连边,跑二分图匹配。

1 /*by SilverN*/ 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 const int mxn=1010;10 int m,n;11 char a[mxn][mxn];12 //13 int idx,idy;14 int hs[mxn][mxn];15 int link[mxn];16 int mp[mxn][mxn];17 bool vis[mxn];18 //19 void init(){20 int i,j;21 for(i=1;i<=n;i++){22 for(j=1;j<=m;j++){23 if(a[i][j]=='*'){24 ++idx;25 while(a[i][j]=='*')hs[i][j++]=idx;26 }27 }28 }29 idy=idx;30 for(j=1;j<=m;j++)31 for(i=1;i<=n;i++){32 if(a[i][j]=='*'){33 ++idy;34 while(a[i][j]=='*'){35 mp[idy][hs[i][j]]=1;36 mp[hs[i++][j]][idy]=1;37 }38 }39 }40 return;41 }42 bool DFS(int u){43 for(int i=1;i<=idy;i++)44 if(!vis[i] && mp[u][i]){45 vis[i]=1;46 if(link[i]==-1 || DFS(link[i])){47 link[i]=u;48 return 1;49 }50 }51 return 0;52 }53 int ans=0;54 void solve(){55 memset(link,-1,sizeof link);56 for(int i=1;i<=idx;i++){57 memset(vis,0,sizeof vis);58 if(DFS(i))ans++;59 }60 return;61 }62 int main(){63 scanf("%d%d",&n,&m);64 int i,j;65 for(i=1;i<=n;i++)66 scanf("%s",a[i]+1);67 init();68 solve();69 printf("%d\n",ans);70 return 0;71 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6047793.html

你可能感兴趣的文章
Win10系统菜单打不开问题的解决,难道是Win10的一个Bug ?
查看>>
好玩的注释
查看>>
【.Net Framework 体积大?】不安装.net framework 也能运行!?原理简介-2(补充)...
查看>>
Maven编译代码的相关命令
查看>>
stingray 页面布局与设计
查看>>
江南白衣整理和开发的java常用工具类
查看>>
Android.mk 文件语法详解
查看>>
android的armeabi和armeabi-v7a
查看>>
android自己定义控件系列教程-----仿新版优酷评论剧集卡片滑动控件
查看>>
emacs的常用配置备份
查看>>
lvs之 lvs+nginx+tomcat_1、tomcat_2+redis(lvs dr 模式)
查看>>
让js中的函数只有一次有效调用的三种常用方法
查看>>
python实现算24的算法
查看>>
Extending a logical volume in a virtual machine running Red Hat or Cent OS (1006371)
查看>>
操作xml格式的字符串的方法(C#)
查看>>
[转]MySQL索引详解(1)
查看>>
poj 3040 Allowance 贪心
查看>>
分享27款最佳的复古风格 WordPress 主题
查看>>
ASP.NET 打包多CSS或JS文件以加快页面加载速度的Handler
查看>>
让“是男人就下到100层”在Android平台上跑起来
查看>>