Oil collection (for Unicom area) more than 2018 School Winter Camp (dfs+ two matching)

Source: Internet
Author: User

Topic:

Links: Https://www.nowcoder.com/acm/contest/76/A
Source: Niu Ke Net

With the issue of oil spills at sea, a new lucrative industry is being created, which is the oil-skimming industry. Today, a large amount of oil floating in the Gulf of Mexico attracts a lot of businessmen's attention. These businessmen have a special kind of plane, can be a scoop over the entire sea 20 meters by 10 meters such a large rectangle. (adjacent or left and right adjacent to the lattice, can not be inclined to come) of course, this requires a scoop of the past is all oil, if there is oil in a ladle there is water, it is meaningless, the resources are completely unusable. Now, businessmen want to know how much oil he can get in this area.

The map is a NXN network, each of which represents a square area of 10mx10m, each of which is marked with oil or water.
Input Description:
Test input contains multiple test data
The first line of the test data gives the number of test data T (t<75)
Each test sample uses the number n (n<50) to represent the size of the map area, followed by n lines with n characters in each row, where the symbol '. ' Indicates the surface of the sea, symbol ' # ' represents the oil surface.
Output Description:
The output format is "Case X:m" (X starting from 1) and M is the maximum amount of oil a trader can get.

Example 1 input
16.......##..........#. #.. #.. ##......
Output
Case 1:3



Test instructions: The Chinese question does not explain



Idea: Way1:dfs is ok ah,,, so simple topic do not know why at that time did not out
Way2: two-point matching


Code Listing 1:
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespacestd;intn,m;Charmp[106][106];intdx[4]={0,1,0,-1};intdy[4]={1,0,-1,0};intAns1,ans2;voidDFS (intIintj) {    intNx,ny; if(i<0|| i>=m| | j<0|| j>=n| | mp[i][j]=='.')        return ; if((i+j)%2==0) ans1++; Elseans2++; MP[I][J]='.';  for(intzz=0;zz<4; zz++) {NX=i+Dx[zz]; NY=j+Dy[zz];    DFS (Nx,ny); }    return ;}intMain () {inti,j,res=0; intT; CIN>>T;  for(into=1; o<=t;o++) {cin>>m; N=m;        GetChar ();  for(i=0; i<m;i++)        {             for(j=0; j<n;j++) {scanf ("%c",&Mp[i][j]);        } getchar (); }         for(i=0; i<m;i++)             for(j=0; j<n;j++)        {            if(mp[i][j]=='#') {ans1=0; Ans2=0;                DFS (I,J); Res+=min (ans1,ans2); }} printf ("Case %d:%d\n", O,res); }    return 0;}

Code 2: (The idea is simply not to write it yourself)

#include <iostream>#include<queue>#include<algorithm>#include<string.h>#include<math.h>#include<map>using namespacestd;Const intmaxn= -;intgirl[maxn],used[maxn],line[maxn][maxn],path[ -][ -],TEMP1,TEMP2;Chara[ -][ -];BOOLFindintx) {     for(intI=1; i<temp2;i++)    if(Line[x][i]&&!used[i])//x and I have a relationship{Used[i]=1; if(girl[i]==0|| Find (Girl[i]))//no master or can make a position;{Girl[i]=x; return true; }    }    return false;}intMain () {intT,n,ans,tt; CIN>>T; TT=1;  while(t--) {ans=0; Temp1=temp2=1; memset (line,0,sizeof(line)); memset (Girl,0,sizeof(girl)); memset (Path,0,sizeof(path)); CIN>>N;  for(intI=1; i<=n;i++)             for(intj=1; j<=n;j++) {cin>>A[i][j]; if((i+j)%2==0) Path[i][j]=temp1++; ElsePath[i][j]=temp2++; }         for(intI=1; i<=n;i++)             for(intj=1; j<=n;j++)            {                if((i+j)%2==1&&a[i][j]=='#')                {                    if(path[i-1][j]>=1&&a[i-1][j]=='#') Line[path[i-1][j]][path[i][j]]=1; if(path[i+1][j]>=1&&a[i+1][j]=='#') Line[path[i+1][j]][path[i][j]]=1; if(path[i][j-1]>=1&&a[i][j-1]=='#') Line[path[i][j-1]][path[i][j]]=1; if(path[i][j+1]>=1&&a[i][j+1]=='#') Line[path[i][j+1]][path[i][j]]=1; }            }         for(intI=1; i<temp1;i++) {memset (used,0,sizeof(used)); if(Find (i)) ans++; } cout<<" Case"<<tt++<<": "<<ans<<Endl; }}

Simple questions

Oil collection (for Unicom area) more than 2018 School Winter camp (dfs+ match)

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.