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 ( 1K100) indicating the number of cases. Each case starts with an integer N ( 1N600) 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
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std; #define N 1210
int cx[N];
int cy[N];
int nx,ny;
int mk[N];
vector<int> map[N];
int ma[N][N];
char g[][]; int path(int u)
{
int len = map[u].size();
for(int i = ; i < len; i ++)
{
int v = map[u][i];
if(!mk[v])
{
mk[v] = ;
if(cy[v] == - || path(cy[v])) ///cy #号块也没有动||cy 也有符合条件的
{
cx[u] = v;
cy[v] = u;
return ;
} }
}
return ;
}
int maxma()
{
int res = ;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
for(int i = ; i < nx; i ++)
{
if(cx[i] == -) ///#号块儿 没动
{
memset(mk,,sizeof(mk));
res += path(i);
//printf("%d---\n",res);
}
}
return res;
}
int main()
{
int t,n;memset(g,,sizeof(g));
//freopen("a.txt","r",stdin);
scanf("%d",&t);
int ca = ;
while(t--)
{
scanf("%d",&n);
for(int i = ;i <= n*n;i ++)
map[i].clear(); ///初始化
int num = ;
//memset(map,0,sizeof(map));
for(int i = ; i <= n; i ++)
{
scanf("%s",g[i]+);
for(int j = ;j <= n;j ++)
if(g[i][j]=='#') ma[i][j] = num++; ///多少#
//printf("||%s\n",g[i]+1);
}
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++) ///符合条件的
{
if(g[i][j] != '#') continue;
if(g[i][j] == '#' && '#' == g[i+][j])
map[ma[i][j]].push_back(ma[i+][j]);
if(g[i][j] == '#' && g[i-][j] == '#')
map[ma[i][j]].push_back(ma[i-][j]);
if(g[i][j] == '#' && g[i][j+] == '#')
map[ma[i][j]].push_back(ma[i][j+]);
if(g[i][j] == '#' && g[i][j-] == '#')
map[ma[i][j]].push_back(ma[i][j-]);
}
nx = ny = num;
printf("Case %d: %d\n",ca++,maxma()/);
}
return ;
}

J - Oil Skimming 二分图的最大匹配的更多相关文章

  1. HDU4185 Oil Skimming 二分图匹配 匈牙利算法

    原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...

  2. HDU4185:Oil Skimming(二分图最大匹配)

    Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】

    Oil Skimming Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  4. HDU4185 Oil Skimming —— 最大匹配

    题目链接:https://vjudge.net/problem/HDU-4185 Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  5. 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)

    如下图:要求最多可以凑成多少对对象 大佬博客: https://blog.csdn.net/cillyb/article/details/55511666 https://blog.csdn.net/ ...

  6. hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)

    Problem Description Thanks to a certain "green" resources company, there is a new profitab ...

  7. Oil Skimming HDU - 4185(匹配板题)

    Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. hdu3729 I'm Telling the Truth (二分图的最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS (Java/ ...

  9. POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)

    题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...

随机推荐

  1. Centos PS1

    PS1="[\[\e[35m\]\u\[\e[m\]\[\e[31m\]->\[\e[m\]\[\e[33m\]\H\[\e[m\]\[\e[31m\]->\[\e[m\]\[\ ...

  2. python——处理xls表格

    因为工作需要,现有一个运营商导出的xls固定电话话费账单. 账单比较详细,而我最终需要的数据只有那个号码这个月用了多少话费的统计结果. 当年没有好好学office,以致于无从下手.泪奔/(ㄒoㄒ)/~ ...

  3. NC 6系分配组织方法

    分配客户的方法 String[] customer = { cuVO.getPk_customer() }; ICustAssignService cs = NCLocator.getInstance ...

  4. NC 6系初始化EJB

    6系开发时,调用远程接口去操作数据时,需先调用EJB. InvocationInfoProxy.getInstance().setUserDataSource(design); InvocationI ...

  5. delphi 7 求无码

    我们知道delphi很多源码,都是没有提供的,比如BDE,一旦有问题,我们也找不到办法解决,那么那些dcu对应的pas是没有公布的呢?笔者做了个统计. 下面是delphi7 的,如果你的程序有用到没有 ...

  6. Python之路(第十六篇)xml模块、datetime模块

    一.xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单, xml比较早,早期许多软件都是用xml,至今很多传统公司如金融行业的很多系统的接口还主要 ...

  7. 52ABP视频学习

    https://study.163.com/course/courseMain.htm?courseId=1005208064 网易视频 https://www.52abp.com/ReadWiki/ ...

  8. windows 与 Linux SOCKET通讯

    windows client 端口 // Def_win_client_socket_test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...

  9. DataTable xml 互相转换

    //测试方法 public static DataTable Test() { string savePath = System.AppDomain.CurrentDomain.BaseDirecto ...

  10. poj-3067(树状数组)

    题目链接:传送门 题意:日本有东城m个城市,西城m个城市,东城与西城相互连线架桥,判断这些桥相交的次数. 思路:两个直线相交就是(x1-x2)*(y1-y2)<0,所以,对x,y进行排序,按照x ...