hdu 4185 二分图最大匹配

时间:2022-11-30 08:56:01

Oil Skimming

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1487    Accepted Submission(s): 612

Problem Description
Thanks
to a certain "green" resources company, there is a new profitable
industry of oil skimming. There are large slicks of crude oil floating
in the Gulf of Mexico just waiting to be scooped up by enterprising oil
barons. One such oil baron has a special plane that can skim the surface
of the water collecting oil on the water's surface. However, each scoop
covers a 10m by 20m rectangle (going either east/west or north/south).
It also requires that the rectangle be completely covered in oil,
otherwise the product is contaminated by pure ocean water and thus
unprofitable! Given a map of an oil slick, the oil baron would like you
to compute the maximum number of scoops that may be extracted. The map
is an NxN grid where each cell represents a 10m square of water, and
each cell is marked as either being covered in oil or pure water.
 
Input
The
input starts with an integer K (1 <= K <= 100) indicating the
number of cases. Each case starts with an integer N (1 <= N <=
600) indicating the size of the square grid. Each of the following N
lines contains N characters that represent the cells of a row in the
grid. A character of '#' represents an oily cell, and a character of '.'
represents a pure water cell.
 
Output
For
each case, one line should be produced, formatted exactly as follows:
"Case X: M" where X is the case number (starting from 1) and M is the
maximum number of scoops of oil that may be extracted.
 
Sample Input
1
6
......
.##...
.##...
....#.
....##
......
 
Sample Output
Case 1: 3
 
Source
 
 
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = ;
const int INF = ;
bool vis[maxn];
int link[maxn];
int G[maxn][maxn];
int x_cnt;
int y_cnt;
int temp[maxn][maxn];
char str[maxn][maxn];
bool find(int u)
{
for(int i = ; i <= y_cnt; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = true;
if(link[i] == - || find(link[i]))
{ link[i] = u;
return true;
}
}
}
return false;
}
int solve()
{
int num = ;
memset(link, -, sizeof(link));
for(int i = ; i <= x_cnt; i++)
{
memset(vis, false, sizeof(vis));
if(find(i))
num++;
}
return num;
}
int main()
{
int t,cnt=;
scanf("%d",&t);
while(t--){
cnt++;
int n;
scanf("%d",&n);
int tmp=;
memset(temp,,sizeof(temp));
memset(G,,sizeof(G));
memset(str,,sizeof(str));
for(int i=;i<n;i++)
{
scanf("%s",&str[i]);
for(int j=;j<n;j++)
if(str[i][j]=='#')
temp[i][j]=++tmp;
}
x_cnt=tmp, y_cnt=tmp;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
if(str[i][j]!='#') continue;
if(i>&&str[i-][j]=='#') G[temp[i][j]][temp[i-][j]]=;
if(i<n-&&str[i+][j]=='#') G[temp[i][j]][temp[i+][j]]=;
if(j>&&str[i][j-]=='#') G[temp[i][j]][temp[i][j-]]=;
if(j<n-&&str[i][j+]=='#') G[temp[i][j]][temp[i][j+]]=;
} printf("Case %d: %d\n",cnt,solve()/);
}
return ;
}

hdu 4185 二分图最大匹配的更多相关文章

  1. hdu 1281 二分图最大匹配

    对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1   Y1 X2   Y2 X3   Y3 ..... Xn   Yn ...

  2. HDU - 2444 二分图最大匹配 之 判断二分图&plus;匈牙利算法

    题意:第一行给出数字n个学生,m条关系,关系表示a与b认识,判断给定数据是否可以构成二分图,如果可以,要两个互相认识的人住一个房间,问最大匹配数(也就是房间需要的最小数量) 思路:要看是否可以构成二分 ...

  3. hdu 4185 二分图匹配

    题意用1*2的木板覆盖矩阵中的‘#’,(木板要覆盖的只能是‘#’),问最多能用几个木板覆盖 将#抽象为二分图的点,一个木板就是一个匹配,注意最后结果要除以2 Sample Input 1 6 .... ...

  4. hdu 4619 二分图最大匹配 ——最大独立集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 #include <cstdio> #include <cmath> # ...

  5. HDU 3279 二分图最大匹配

    DES: 就是说对每个人都给你一个区间.但一个人只匹配一个数.问你满足匹配的人的序号字典序最大时的最大匹配是什么. 前几天刚做的UVALive 6322...当然是不一样的...那个要求的最大匹配的个 ...

  6. hdu 3729&lpar;二分图最大匹配&rpar;

    I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. HDU:过山车(二分图最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2063 题意:有m个男,n个女,和 k 条边,求有多少对男女可以搭配. 思路:裸的二分图最大匹配,匈牙利算法. 枚 ...

  8. &lbrack;HDU&rsqb; 2063 过山车&lpar;二分图最大匹配&rpar;

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063 女生为X集合,男生为Y集合,求二分图最大匹配数即可. #include<cstdio&gt ...

  9. HDU 3829 Cat VS Dog &sol; NBUT 1305 Cat VS Dog(二分图最大匹配)

    HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配) Description The zoo have N cats and M dogs, toda ...

随机推荐

  1. MySQL存储引擎--MyISAM与InnoDB区别

    InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.MyISA ...

  2. selenium第二课(脚本录制seleniumIDE的使用)

    一.Selenium也具有录制功能,可以web中回放,录制的脚本可以转换为java.python.ruby.php等多种脚本语言.seleniumIDE是Firefox的一个插件,依附于Firefox ...

  3. H5案例分享:html5重力感应事件

    html5重力感应事件 一.手机重力感应图形分析 1.设备围绕z轴的旋转角度为α,α角度的取值范围在[0,360). 设备在初始位置,与地球(XYZ)和身体(XYZ)某个位置对齐. 设备围绕z轴的旋转 ...

  4. CSS继承总结

    CSS的一个重要特征就是继承,它是依赖于祖先-后代的关系的.继承是一种机制,它允许样式不仅可以应用于某个特定的元素,还可以应用于它的后代. CSS可以继承的属性有: 1.文字相关:font-famil ...

  5. subeclipse 安装

    网址:http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA

  6. C&num;快速排序详解

    使用快速排序法对一列数字进行排序的过程 快速排序使用分治法(Divide and conquer)策略来把一个序列(list)分为两个子序列(sub-lists). 步骤为: 从数列中挑出一个元素,称 ...

  7. cocos2d-x3&period;0 SpriteFrameCache

    bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ...

  8. hibernate 单元測试框架

    hibernate在写数据库配置文件时很的不确定,必须进行必要的測试保证数据库结构的正确性.所以能够应用junit进行測试. 使用junit很easy,eclipse仅仅须要右键项目新建一个junit ...

  9. Java堆栈(转)

     Java栈与堆 ----对这两个概念的不明好久,最终找到一篇好文,拿来共享 1. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方.与C++不同,Java自己主动管理栈和堆, ...

  10. java自带的监控工具VisualVM一

    转自:http://www.cnblogs.com/wade-xu/p/4369094.html 这篇总结的很不错(本人亲自操手学习),留着以后复习备用,很适合入门级的学习者: VisualVM 是一 ...