HDU 4185 Oil Skimming 二分图匹配

Oil Skimming

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


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
The 2011 South Pacific Programming Contest
 



裸的匹配。。不说了。。


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

#define PB push_back
#define MP make_pair
#define CLR(vis) memset(vis,0,sizeof(vis))
#define MST(vis,pos) memset(vis,pos,sizeof(vis))
#define MAX3(a,b,c) max(a,max(b,c))
#define MAX4(a,b,c,d) max(max(a,b),max(c,d))
#define MIN3(a,b,c) min(a,min(b,c))
#define MIN4(a,b,c,d) min(min(a,b),min(c,d))
#define PI acos(-1.0)
#define INF 0x7FFFFFFF
#define LINF 1000000000000000000LL
#define eps 1e-8

typedef long long ll;
typedef unsigned long long ull;


const int mm=1111111;
const int mn=7777;

int node,s,t,edge,max_flow;

int ver[mm],cap[mm],flow[mm],next[mm];

int head[mn],work[mn],dis[mn],q[mn];

inline void init(int _node,int _s,int _t)
{
    node=_node, s=_s, t=_t;
    for(int i=0;i0)
        {
           flow[i]+=temp;
           flow[i^1]-=temp;
           return temp;
        }
    }
    return 0;
}

int Dinic_flow()
{
    int res,i;
    while(Dinic_bfs())
    {
        for(i=0;i>tt;
    int n;
    char str[666][666];
    int cas=1;
    while(tt--)
    {
        cin>>n;
        int S,T;
        for(int i=1;i<=n;i++)
            scanf("%s",str[i]+1);
        S=0,T=2*n*n+1;
        init(2*n*n+2,S,T);
        //cout<=1 && i+dx[k]<=n && j+dy[k]>=1 && j+dy[k]<=n && str[i+dx[k]][j+dy[k]]=='#')
                            addedge((i-1)*n+j,(i+dx[k]-1)*n+j+dy[k]+n*n,1);
                    }
                }
            }
        }
        int ans=Dinic_flow();
        printf("Case %d: %d\n",cas++,ans/2);

    }
    return 0;
}


你可能感兴趣的:(图论)