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 ( 1
K
100) indicating the number of cases. Each case starts with an integer N ( 1
N
600) 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种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...
随机推荐
- POJ 2135.Farm Tour 消负圈法最小费用最大流
Evacuation Plan Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4914 Accepted: 1284 ...
- Spring 如何保证后置处理器的执行顺序 - OrderComparator
Spring 如何保证后置处理器的执行顺序 - OrderComparator Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.htm ...
- 类名.class 与 类名.this 详解
类名.class 与 类名.this 详解 今天在看 PropertyPlaceholderConfigurer 源码时,突然看到一个 PropertyPlaceholderConfigurer.th ...
- MySQLdb与sqlalchemy的简单封装
一:MySQLdb # !/usr/bin/python # -*- coding: UTF-8 -*- import MySQLdb import MySQLdb.cursors import co ...
- “matplotlib display text must have all code points < 128 or use Unicode strings”解决方法
import sys reload(sys) sys.setdefaultencoding('utf-8') 插入以上代码,便可解决.
- 在myeclipse上发布自己的webservice
什么是WebServices? 它是一种构建应用程序的普遍模型,可以在任何支持网络通信的操作系统中实施运行;它是一种新的web应用程序分支,是自包含.自描述.模块化的应用,可以发布.定位.通过w ...
- python之初级篇2
一.数字类型 1)整数 int 类型 - bit_length() # 查询以二进制表示一个数字的值所需的位数 - int.from_bytes(bytes,byteorder) # 返回给定字节数组 ...
- vue导航栏实时获取URL设置当前样式,刷新也存在!
很low 别喷, template代码: <div class="tab-itme"> <ul @click="clickit()"> ...
- 2018.11.01 loj#2319. 「NOIP2017」列队(线段树)
传送门 唉突然回忆起去年去noipnoipnoip提高组试水然后省二滚粗的悲惨经历... 往事不堪回首. 所以说考场上真的有debuffdebuffdebuff啊!!!虽然当时我也不会权值线段树 这道 ...
- MYSQL 事务测试
mysql 事务测试 创建张表 lock1 增加字段 id,name . 增加两条记录 1,a 2,b 启动第一个会话 BEGIN; update lock1 set name='c' where i ...