Hdu4185 Oil Skimming
Oil Skimming
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.
in the grid. A character of '#' represents an oily cell, and a character of '.' represents a pure water cell.
6
......
.##...
.##...
....#.
....##
......
————————————————————————————————————
题目的意思是给出一张图#表示油田,用1*2的矩阵去盖在#上,问最多可以放多少个#
思路:题目就是拿行列和为奇数的点和行列和为偶的点匹配,问最多可以多少,图大hash一下
其实复杂度还是绷不住,我也没什么思路,但看了网上的都是直接上,数据水了
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
const int MAXN=1005;
int uN,vN; //u,v数目
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int link[MAXN];
int ha[MAXN][MAXN];
char s[MAXN];
int dir[4][2]= {{-1,0},{1,0},{0,-1},{0,1}}; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
} int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int m,n,k,x,y,T;
int q=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); int cnt=0;
memset(ha,-1,sizeof ha);
for(int i=0; i<n; i++)
{
scanf("%s",s);
for(int j=0; j<n; j++)
{
if(s[j]=='#')
ha[i][j]=cnt++;
}
}
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if(ha[i][j]!=-1)
{
for(int k=0; k<4; k++)
{
int xx=i+dir[k][0];
int yy=j+dir[k][1];
if(xx>=0&&xx<n&&yy>=0&&yy<n&&ha[xx][yy]!=-1)
{
g[ha[i][j]][ha[xx][yy]]=1;
}
} }
uN=vN=cnt;
printf("Case %d: %d\n",q++,hungary()/2); }
return 0;
}
Hdu4185 Oil Skimming的更多相关文章
- 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/ ...
- HDU4185 Oil Skimming 二分图匹配 匈牙利算法
原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...
- hdu4185 Oil Skimming(偶匹配)
<span style="font-family: Arial; font-size: 14.3999996185303px; line-height: 26px;"> ...
- HDU4185:Oil Skimming(二分图最大匹配)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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 ...
- Oil Skimming HDU - 4185(匹配板题)
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 ...
随机推荐
- iOS.XcodeUsage
1. Customizing Xcode File Templates http://blog.highorderbit.com/2009/03/15/customizing-xcode-cocoa- ...
- python下的MySQL数据库编程
https://www.tutorialspoint.com/python/python_database_access.htm if you need to access an Oracle dat ...
- 在eclipse中import java web项目时遇到的一些问题并将该项目通过tomcat发布
1.首先是import一个新的项目,会将已有的项目import到working space中,注意,你现在的项目路径就在working space了,而不是已有的项目路径! 2.点击eclipse上面 ...
- [Robot Framework] 校验字符串中是否包含某个子字符串,校验同时满足两个条件中任意一个
${tWarningMessage} Run Keyword If ${tIfExist} AutoItLibrary.Win Get Text Generate Fee Data warning m ...
- 查询数据库中的表格---通过构造方法将数据存入到List集合中---遍历进行输出
package cn.jy.demo; import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.Res ...
- 搭建java环境和java学习
https://blog.csdn.net/fishe_r/article/details/18863447 其中的 java配置文件用: { "shell_cmd": " ...
- tomcat 配置域名访问应用
<Host appBase="webapps" autoDeploy="true" name="www.XXX.com" unpack ...
- Gazebo: Could not find parameter robot_description on parameter server
robot_state_publisher looks for the parameter "robot_description" by default. The robot_st ...
- pkg_resources.DistributionNotFound: The 'catkin-pkg==0.4.9' distribution was not found
个人感觉是python2与python3在ros中的差异导致的, 问题一:Traceback (most recent call last): File "/usr/bin/rosdep& ...
- centos配置虚拟用户再也不用那么麻烦了
http://wiki.centos.org/HowTos/Chroot_Vsftpd_with_non-system_users yum install -y vsftpd db4-utils vs ...