HDU 4185 Oil Skimming(最大二分匹配)

题目链接

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

题意:就是拿1*2的矩形去覆盖只有“#”的点,问最多能用多少个矩形。

题解:首先这个题,我们能够想到要用匈牙利算法算法,这是一个平面,我们用匈牙利算法算法很难用两个数组,所以我们要将图中每个“#”离散化保存。然后我们保存每个“#”点所能匹配的坐标,最后二分匹配就好了,细节看代码。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
const int maxn=6e2+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
#define me(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&(-x)
#define mid (l+r)/2
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
int dir[4][2]= {0,1,0,-1,1,0,-1,0};
typedef long long ll;
using namespace std;
char maps[maxn][maxn];
bool vis[maxn];
int head[maxn*maxn],len,n;
int maps1[maxn][maxn];
int d[maxn*maxn];
struct node
{
    int v,next;
} a[maxn*maxn];
void init()
{
    me(head,-1);
    len=0;
}
void add_edge(int u,int v)
{
    a[len].v=v;
    a[len].next=head[u];
    head[u]=len++;
}
int check(int x,int y)
{
    if(x<0||y<0||x>=n||y>=n||maps[x][y]=='.')
        return 0;
    return 1;
}
void Creat()///将能够构成1*2的全部存起来
{
    for(int i=0; i

 

你可能感兴趣的:(二分匹配,图论)