hdu 4185 二分图最大匹配
Oil Skimming
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1487 Accepted Submission(s): 612
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 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.
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.
6
......
.##...
.##...
....#.
....##
......
#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 二分图最大匹配的更多相关文章
- hdu 1281 二分图最大匹配
对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1 Y1 X2 Y2 X3 Y3 ..... Xn Yn ...
- HDU - 2444 二分图最大匹配 之 判断二分图+匈牙利算法
题意:第一行给出数字n个学生,m条关系,关系表示a与b认识,判断给定数据是否可以构成二分图,如果可以,要两个互相认识的人住一个房间,问最大匹配数(也就是房间需要的最小数量) 思路:要看是否可以构成二分 ...
- hdu 4185 二分图匹配
题意用1*2的木板覆盖矩阵中的‘#’,(木板要覆盖的只能是‘#’),问最多能用几个木板覆盖 将#抽象为二分图的点,一个木板就是一个匹配,注意最后结果要除以2 Sample Input 1 6 .... ...
- hdu 4619 二分图最大匹配 ——最大独立集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 #include <cstdio> #include <cmath> # ...
- HDU 3279 二分图最大匹配
DES: 就是说对每个人都给你一个区间.但一个人只匹配一个数.问你满足匹配的人的序号字典序最大时的最大匹配是什么. 前几天刚做的UVALive 6322...当然是不一样的...那个要求的最大匹配的个 ...
- hdu 3729(二分图最大匹配)
I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU:过山车(二分图最大匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2063 题意:有m个男,n个女,和 k 条边,求有多少对男女可以搭配. 思路:裸的二分图最大匹配,匈牙利算法. 枚 ...
- [HDU] 2063 过山车(二分图最大匹配)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063 女生为X集合,男生为Y集合,求二分图最大匹配数即可. #include<cstdio> ...
- HDU 3829 Cat VS Dog / 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 ...
随机推荐
- JavaScript模块化开发的那些事
模块化开发在编程开发中是一个非常重要的概念,一个优秀的模块化项目的后期维护成本可以大大降低.本文主要介绍了JavaScript模块化开发的那些事,文中通过一个小故事比较直观地阐述了模块化开发的过程. ...
- tensorflow构建CNN模型时的常用接口函数
(1)tf.nn.max_pool()函数 解释: tf.nn.max_pool(value, ksize, strides, padding, data_format='NHWC', name=No ...
- python_63_装饰器6
#decorator意思:1.装饰器 2.语法糖 import time user,passwd='qi','123' def auth(func): def wrappper(*args, **kw ...
- 在C++类中使用dllimport和dllexport导出,
在Windows平台下: 您可以使用dllimport或dllexport属性声明C ++类.这些形式意味着导入或导出整个类.以这种方式导出的类称为可导出类. 以下示例定义可导出的类.导出其所有成员函 ...
- yield 生成器的运行机制
yield 生成器的运行机制 当你问生成器要一个数时,生成器会执行,直至出现 yield 语句,生成器把 yield 的参数给你,之后生成器就不会往下继续运行. 当你问他要下一个数时,他会从上次的状态 ...
- 简述apache,php,mysql三者的关系
转自:http://blog.csdn.net/w1365966490/article/details/8218959 Apache web 服务器软件.同类产品有微软的 IIS 等.功能是让某台电脑 ...
- vue axios 攻略
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 特点: 从浏览器中创建 XMLHttpRequest 从 node.js 发出 http 请求 支持 ...
- <%%>用法初步认识
<%%>是用于向客户端插入服务器代码所使用的一种标记 例如为了在HTML页面上展示由服务器提供的当前用户的某条信息或名字等便可使用 前台 <a href="home.asp ...
- ATMstart
import os, sys BASE_DIR = os.path.dirname(__file__)sys.path.append(BASE_DIR) from core import src if ...
- JZOJ 5773. 【NOIP2008模拟】简单数学题
5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms Memory Limits ...