J - Oil Skimming 二分图的最大匹配
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 二分图的最大匹配的更多相关文章
- HDU4185 Oil Skimming 二分图匹配 匈牙利算法
原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...
- HDU4185:Oil Skimming(二分图最大匹配)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】
Oil Skimming Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- HDU4185 Oil Skimming —— 最大匹配
题目链接:https://vjudge.net/problem/HDU-4185 Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memo ...
- 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)
如下图:要求最多可以凑成多少对对象 大佬博客: https://blog.csdn.net/cillyb/article/details/55511666 https://blog.csdn.net/ ...
- hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)
Problem Description Thanks to a certain "green" resources company, there is a new profitab ...
- Oil Skimming HDU - 4185(匹配板题)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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/ ...
- POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)
题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...
随机推荐
- BZOJ 3932 [CQOI2015]任务查询系统 - 差分 + 主席树
Solution 差分就好了, 在$s_i$ 的点+1, $e_i + 1$ 的点 - 1. 查询的时候注意$l == r$ 要返回 $k * b[l]$ ,而不是$sum[node] $因为当前位置 ...
- Sliding Window Maximum LT239
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- js使用sessionStorage、cookie保存token
本文是参考别人的博客写的,图片直接用的别人的 1.Token:token是客户端频繁向服务器端请求数据,服务器频繁的去数据库查询用户名和密码进行对比,判断用户名和密码正确与否,并作出相应的提示,在这样 ...
- 深入理解python里面类的对象的赋值
class T(): def __init__(self): self.name= pass a=T() a.name= b=a #深入理解类,类里面的对象的赋值是指针赋值,也就是同时变的 b.nam ...
- android windows的一些item属性
<item name="android:windowFrame">@null</item> :Dialog的windowFrame框为无 <item ...
- 2019.01.14 bzoj2752: [HAOI2012]高速公路(线段树)
传送门 线段树菜题. 题意简述:给一条nnn个点的链,链有边权,支持区间修改边权,查询在一段区间内随机选择不同的起点和终点路径的期望总边权和. 思路:考虑每条边的贡献. 考虑对于一段区间[l,r][l ...
- android studio友盟分享demo运行报错Gradle's dependency cache may be corrupt解决方法
gradle-wrapper.properties里修改了gradle的版本,与之前没有报错的项目gradle版本一致.
- java常用设计模式六:适配器模式
一.定义 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作.比如以下的场景: 用手机充电为例,有一个手机的插孔是TypeC口,现在只 ...
- java常用设计模式二:工厂模式
1.简单工厂模式(静态工厂方法模式) 抽象实例: public interface People { void talk(); } 具体实例: public class Doctor implemen ...
- 使用vue,react,angular等框架和不使用框架使用jquery的优缺点
jquery和vue react等框架有着本质上的区别,从jquery到vue.react 或者说是到mvvm的转变,是一个思想的转变,是将原有的直接操作dom的思想转变到操作数据上去. vue更关注 ...