O - Muddy Fields
来源poj2226
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.
有点像小行星,但是它值能覆盖连续的泥池,所以要构图,将横着放的板子和纵放的板子编号,然后连起来算最小点覆盖
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1017;
int pre[N];
int visit[N],line[N][N],line1[N][N],line2[N][N];
char Map[N][N];
int n,m,y,x;
int cas,cas1;
bool find(int x)
{
rep(i,1,cas1+1)
{
if(line[x][i]&&visit[i]==0)
{
visit[i]=1;
if(pre[i]==0||find(pre[i]))
{
pre[i]=x;
return true;
}
}
}
return false;
}
void deal()
{
cas=0;
rep(i,1,n+1)
{
rep(j,1,m+1)
{
if(Map[i][j]=='*')
{
cas++;
while(j<=m&&Map[i][j]=='*')
{
line1[i][j]=cas;
j++;
}
}
}
}
cas1=0;
rep(j,1,m+1)
{
rep(i,1,n+1)
{
if(Map[i][j]=='*')
{
cas1++;
while(i<=n&&Map[i][j]=='*')
{
line2[i][j]=cas1;
i++;
}
}
}
}
rep(i,1,n+1)
rep(j,1,m+1)
if(Map[i][j]=='*')
line[line1[i][j]][line2[i][j]]=1;
}
int main()
{
while(~sf("%d%d",&n,&m))
{
mm(Map,'0');
mm(line,0);
mm(line2,0);
mm(line1,0);
mm(pre,0);
for(int i = 1; i <=n; i++)
{
for(int j = 1; j <= m; j++)
{
cin>>Map[i][j];
}
}
deal();
int ans=0;
rep(i,1,cas+1)
{
mm(visit,0);
if(find(i))
ans++;
}
pf("%d\n",ans);
}
return 0;
}
O - 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 (转化成二分图的最小覆盖)
http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2226 Muddy Fields(最小顶点覆盖)
POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...
- Muddy Fields
Muddy Fields Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submi ...
- bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖
链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
- poj 2226 Muddy Fields (二分匹配)
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7340 Accepted: 2715 Desc ...
- poj Muddy Fields
Muddy Fields 原题去我创的专题里找,在文件夹首页. 题目: 给出N*M矩阵.当中*表示泥土,.表示小草.要你用最少的木板把泥土覆盖. 木板长度不限.可是仅仅能水平和竖直. 行列式二分匹配配 ...
- BNUOJ 2345 Muddy Fields
Muddy Fields Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original I ...
- POJ Muddy Fields 泥泞的牧场 二分图
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13235 Accepted: 4879 汪星人 ...
- POJ2226 Muddy Fields
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10149 Accepted: 3783 Description Rain ...
随机推荐
- 在 iOS 中信任手动安装的证书描述文件
在 iOS 10.3 及更高版本中,手动安装包含证书有效负载的描述文件时,这个证书不会自动受 SSL 信任. 在安装通过电子邮件发送给您或从网站下载的描述文件时,您必须手动开启受 SSL 信任. ...
- Catch a Memory Access Violation in C++
From: https://stackoverflow.com/questions/16612444/catch-a-memory-access-violation-in-c In C++, is ...
- android编码学习
虽然以下博客有点老,但很清晰,有不明白的基础知识,可以来这里找找. 2015年最新Android基础入门教程目录(完结版) 1. 环境配置 Android stodio gradle配置踩过的坑 An ...
- 天府大讲堂:5G时代的物联网发展趋势与产业变革
摘要:国家973物联网首席科学家,中科院上海微系统与信息技术研究所副所长,无锡物联网产业研究院院长刘海涛教授讲授的5G时代的物联网发展趋势与产业变革意义深刻.作者根据天府大讲堂听讲内容加工整理所得,旨 ...
- C#使用HttpWebRequest和HttpWebResponse上传文件示例
C#使用HttpWebRequest和HttpWebResponse上传文件示例 1.HttpHelper类: 复制内容到剪贴板程序代码 using System;using System.Colle ...
- Mac NVM 配置
1.NVM 简介 NVM(node version manager)是一个可以让你在同一台机器上安装和切换不同版本 node 的工具. GitHub 地址 2.NVM 环境配置 2.1 安装 NVM ...
- Swift Struct 结构体
前言 Swift 语言有两种基本的数据类型,即类(class)和结构体(struct),class 这样的概念大家不会陌生,而 struct 也并不是什么新的概念,在 Objective-C 和 C ...
- IIS7设置将域名不带www跳转到带www上
很多朋友在IIS环境中搭建好网站后,习惯性将带www和不带www的域名都绑定到一个网站上,这样做虽然两个域名都能访问,但容易造成权重分散,从而导致网站权重降低.其实我们可以将访问不带www的域名自动跳 ...
- [20180312]进程管理其中的SQL Server进程占用内存远远大于SQL server内部统计出来的内存
sql server 统计出来的内存,不管是这个,还是dbcc memorystatus,和进程管理器中内存差距很大,差不多有70G的差异. 具体原因不止,可能是内存泄漏,目前只能通过重启服务解决 ...
- npm install 项目安装遇到问题
npm cache clean/clear --force