H - Oil Skimming (挖石油)
二分匹配,计算出里边有多少个‘#’,将这些编号,之后查找,如果他的周围是“#”,就将这两个连一条边。之后跑一边匈牙利;点数就是‘#’数目;
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.
InputThe 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.OutputFor 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 <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
char mp[650][650];
int g[650][650];
int vis[1000];
int dis[1000];
int dp[1000][1000];//新图的地图
int n,t;
int v;//建立新图的边
/* 匈 牙 利 算 法 */
int find(int x)
{
for(int i=0;i<v;i++)
{
if(!vis[i]&&dp[x][i])
{
vis[i]=1;
if(dis[i]==0||find(dis[i]))
{
dis[i]=x;
return 1;
}
}
}
return 0;
}
int maxp()
{
int ans=0;
memset(dis,0,sizeof(dis));
for(int i=0;i<v;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
ans++;
}
return ans;
}
int main()
{
int t,icase=1;
cin>>t;
while(t--)
{
cin>>n;
int cnt=0,ans=0;
memset(mp,0,sizeof(mp));
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)
{
scanf("%s",mp[i]);
for(int j=0;j<n;j++)
{
if(mp[i][j]=='#')//
g[i][j]=cnt++;
}
}
v=cnt;//新图的边
for(int i=0;i<n;i++)/*保存新图,即将题给的图转换成点与点之间边的关系*/
{
for(int j=0;j<n;j++)
{
if(mp[i][j]!='#') continue;
if(i>0&&mp[i-1][j]=='#') dp[g[i-1][j]][g[i][j]]=1;
if(i<n-1&&mp[i+1][j]=='#') dp[g[i+1][j]][g[i][j]]=1;
if(j>0&&mp[i][j-1]=='#') dp[g[i][j-1]][g[i][j]]=1;
if(j<n-1&&mp[i][j+1]=='#') dp[g[i][j+1]][g[i][j]]=1;
}
}
ans=maxp();
printf("Case %d: %d\n",icase++,ans/2);
}
}
H - Oil Skimming (挖石油)的更多相关文章
- hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)
Problem Description Thanks to a certain "green" resources company, there is a new profitab ...
- J - Oil Skimming 二分图的最大匹配
Description Thanks to a certain "green" resources company, there is a new profitable indus ...
- HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】
Oil Skimming Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- HDU 1241 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- Hdu4185 Oil Skimming
Oil Skimming Problem Description Thanks to a certain "green" resources company, there is a ...
- Oil Skimming HDU - 4185(匹配板题)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU4185:Oil Skimming(二分图最大匹配)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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/ ...
随机推荐
- 解放双手,markdown文章神器,Typora+PicGo+七牛云图床实现自动上传图片
本文主要分享使用Typora作为Markdown编辑器,PicGo为上传图片工具,使用七牛云做存储来解放双手实现图片的自动化上传与管理.提高写作效率,提升逼格.用过 Markdown 的朋友一定会深深 ...
- 【MySQL】CentOS7中使用systemctl工具管理启动和停止MySQL
centos7以前版本,可以使用这个/etc/init.d/mysqld start 来启动mysql 但是centos7之后,通过systemctl start mysqld.service 这个要 ...
- LeetCode404.左叶子之和
题目 法一.广度优先搜索 1 class Solution { 2 public: 3 int sumOfLeftLeaves(TreeNode* root) { 4 if(root == NULL) ...
- CTFshow萌新赛-密码学签到
查看密码信息 猜测为base家族 存在"^"符号,所以应该是在base64以上 使用base85解密 成功拿到flag
- SWPU2019
一.题目打开介绍 这是题目本身打开的样子,继续进入题目 二.做题 简单的登陆界面和注册界面,没有sql注入已经尝试 申请发布广告 习惯性的测试 然后开始尝试注入,抓包, 两个都要,经过union注入判 ...
- Nacos 服务配置中心
1.因为项目是微服务分布式项目,每个微服务都需要用到配置中心,所以第一步我们先在common中添加相应的依赖 <dependency> <groupId>com.alibaba ...
- 阿里云VOD(三)
一.视频播放器 参考文档:https://help.aliyun.com/document_detail/125570.html?spm=a2c4g.11186623.6.1083.1c53448bl ...
- 阿里云RDS物理备份恢复到本地
一:业务场景 验证阿里云备份文件可用性 二:恢复到本地过程中遇到的问题 1.修改密码报错 2.自定义函数不可用 三:恢复步骤 1.xtrabackup安装使用 请参考:https://www.cnbl ...
- JSAAS BPM快速开发平台-企业管理软件,专属你的企业管家
前言: 2020年,企业该如何去选择合适的信息化规划管理软件,基于目前社会软件杂乱无章,选择企业业务贴近的管理软件,甚是困难,市场上一些大品牌公司的产品,定位高,价格高,扩展难,等等一系列的问题,对于 ...
- MAX232数据方向
在调试一个新板子的时候,串口调试从来都是放在前面的,而由于是一个新板子,电路图也是新的,因此有时候不知道串口线结对了没有,这个时候可能会对照PCB和原理图去看一下,但有时候看的人会很迷糊,因为不同的人 ...