Hdu4185 Oil Skimming

Oil Skimming


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
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   4186  4177  4178  4180  4181 
 

————————————————————————————————————

题目的意思是给出一张图#表示油田,用1*2的矩阵去盖在#上,问最多可以放多少个#

思路:题目就是拿行列和为奇数的点和行列和为偶的点匹配,问最多可以多少,图大hash一下

其实复杂度还是绷不住,我也没什么思路,但看了网上的都是直接上,数据水了

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;
const int MAXN=1005;
int uN,vN;  //u,v数目
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int link[MAXN];
int ha[MAXN][MAXN];
char s[MAXN];
int dir[4][2]= {{-1,0},{1,0},{0,-1},{0,1}};

bool dfs(int u)
{
    int v;
    for(v=0; v<vN; v++)
        if(g[u][v]&&!used[v])
        {
            used[v]=true;
            if(linker[v]==-1||dfs(linker[v]))
            {
                linker[v]=u;
                return true;
            }
        }
    return false;
}

int hungary()
{
    int res=0;
    int u;
    memset(linker,-1,sizeof(linker));
    for(u=0; u<uN; u++)
    {
        memset(used,0,sizeof(used));
        if(dfs(u))  res++;
    }
    return res;
}

int main()
{
    int m,n,k,x,y,T;
    int q=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);

        int cnt=0;
        memset(ha,-1,sizeof ha);
        for(int i=0; i<n; i++)
        {
            scanf("%s",s);
            for(int j=0; j<n; j++)
            {
                if(s[j]=='#')
                    ha[i][j]=cnt++;
            }
        }
        memset(g,0,sizeof g);
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                if(ha[i][j]!=-1)
                {
                    for(int k=0; k<4; k++)
                    {
                        int xx=i+dir[k][0];
                        int yy=j+dir[k][1];
                        if(xx>=0&&xx<n&&yy>=0&&yy<n&&ha[xx][yy]!=-1)
                        {
                            g[ha[i][j]][ha[xx][yy]]=1;
                        }
                    }

                }
        uN=vN=cnt;
        printf("Case %d: %d\n",q++,hungary()/2);

    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值