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 二分图最大匹配 之 判断二分图+匈牙利算法

    题意:第一行给出数字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(二分图最大匹配)

    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. [HDU] 2063 过山车(二分图最大匹配)

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

  9. 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 ...

随机推荐

  1. python_32_文件操作1

    #目录里先创建一个yesterday文件 '''对文件操作流程: 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 ''' print(open('yesterday',enc ...

  2. 解决session过期跳转到登录页并跳出iframe框架(或者layui弹出层)

    当用户长时间停留在管理界面没有操作,等到session过期后,进行了操作,那么只是iframe跳转到login页面,这不是我们想要的结果.解决方法:在login页面加一个逻辑判断: <scrip ...

  3. python 线程even

    import threading,time import random def door(nums): num=1#电梯在一楼 while True: print("this door is ...

  4. unsigned __int64 打印方法

    原文出处 long 和 int 范围是[-2^31,2^31),即-2147483648~2147483647. 而unsigned范围是[0,2^32),即0~4294967295.也就是说,常规的 ...

  5. CSVDE

    csvde -f C:\export_OrganizationalUnit.csv -r '(objectClass=organizationalUnit)' -l 'displayName,prox ...

  6. iOS进阶面试题

    1. 风格纠错题 修改完的代码: 修改方法有很多种,现给出一种做示例: // .h文件 // http://weibo.com/luohanchenyilong/ // https://github. ...

  7. C/C++程序基础 (二)常用知识点

    使用宏实现max 注意括号在宏内的使用 #define MAX(x, y) ( ( (x) > (y) ) ? (x) : (y) ) 宏参数连接 a##e##b 转化为字符串 #a const ...

  8. Python3爬取人人网(校内网)个人照片及朋友照片,并一键下载到本地~~~附源代码

    题记: 11月14日早晨8点,人人网发布公告,宣布人人公司将人人网社交平台业务相关资产以2000万美元的现金加4000万美元的股票对价出售予北京多牛传媒,自此,人人公司将专注于境内的二手车业务和在美国 ...

  9. A1027 Colors in Mars (20)(20 分)

    A1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar ...

  10. poj 3104 晾衣服问题 最大化最小值

    题意:n件衣服各含有ai水分,自然干一分钟一个单位,放烘干机一分钟k个单位,问:最短时间? 思路: mid为最短时间 如果 a[i]-mid>0说明需要放入烘干机去烘干 烘干的时间为x  那么满 ...