Hdu4185 Oil Skimming

Source: Internet
Author: User
Tags bool

Oil Skimming
Problem Description Thanks to a certain "green" resources company, there are a new profitable industry of oil skimming. There is large slicks of crude oil floating in the Gulf of Mexico just waiting to being scooped up by enterprising oil baron S. One such oil baron have 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 was completely covered in oil, otherwise the product was contaminated by pure ocean wate R and thus unprofitable! Given a map of the oil slick, the oil baron would like you to compute the maximum number of scoops, is may 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 I n Oil or pure water.
Input the input starts with an integer k (1 <= k <=) indicating the number of cases. Each case is starts with an integer n (1 <= n <=) indicating the size of the square grid. Each of the following n lines contains n characters this 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 (s Tarting from 1) and M are the maximum number of scoops of oil which may be extracted.
Sample Input

1 6 ..... ##... . ##... ....#. ....## ......
Sample Output
Case 1:3
Source the Pacific programming Contest
Recommend LCY | We have carefully selected several similar problems for you:4186 4177 4178 4180 4181

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

The title means to give a picture of the oil field, using the 1*2 matrix to cover the #, ask the maximum number of places to put #

Idea: The title is to take the ranks and for the odd points and the ranks and for the point of matching, ask the most can be how much, figure big Hash

In fact, the complexity is still stretched, I have no idea, but looked at the Internet are directly on, data water

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath > #include <algorithm> #include <queue> #include <vector> #include <set> #include <stack&
Gt

#include <map> #include <climits> using namespace std;
#define LL Long Long const int INF = 0X3F3F3F3F;
const int maxn=1005;  int un,vn;
u,v number 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; }




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.