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.
1 6 ...... .##... .##... ....#. ....## ......
Case 1: 3
和POJ3020类似
题意:给一张图,问最大的连续两个格子数目有多少。
建图:用横纵坐标和为偶数为x边,对该点想上下左右寻找(上下左右点必为奇数为y边),建二分图。用匈牙利算法就行啦。
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
char mp[666][666];
vector<int> g[1999];
int n,m,mm,my[1999],ct[666][666];
int dx[]={0,0,-1,1},dy[]={1,-1,0,0};
bool vis[1999];
int dfs(int x)
{
for(int i=0;i<g[x].size();i++)
{
int y=g[x][i];
if(vis[y])continue;
vis[y]=true;
if(my[y]==-1||dfs(my[y]))
{
my[y]=x;
return 1;
}
}
return 0;
}
int maxmacth()
{
int ret=0,x,y;
memset(my,-1,sizeof(my));
for(int i=1;i<=m;i++)
{
memset(vis,false,sizeof(vis));
if(dfs(i))ret++;
}
return ret;
}
int main()
{
int tat,x,y,cas=1;
scanf("%d",&tat);
while(tat--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf(" %s",mp[i]+1);
}
m=mm=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if((i+j)%2)
ct[i][j]=++m;
else
ct[i][j]=++mm;
}
}
for(int i=1;i<=m;i++)
{
g[i].clear();
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if((i+j)%2)continue;
if(mp[i][j]=='#')
for(int k=0;k<4;k++)
{
x=i+dx[k];
y=j+dy[k];
if(x<1||y<1||x>n||y>n)continue;
if(mp[x][y]!='#')continue;
g[ct[i][j]].push_back(ct[x][y]);
}
}
}
/* for(int i=1;i<=m;i++)
{
for(int j=0;j<g[i].size();j++)
cout<<i<<" "<<g[i][j]<<endl;
}
*/
printf("Case %d: %d\n",cas++,maxmacth());
}
return 0;
}