HDU4185 Oil Skimming(二分图匹配,匈牙利算法)
来源:互联网 发布:臣妾做不到网络歌曲 编辑:程序博客网 时间:2024/05/01 11:29
Problem 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
16.......##....##.......#.....##......
Sample Output
Case 1: 3
思路
有一个石油大亨要在一片#
代表这个地方是石油,.
代表这个地方是海水,问在这一片水域,最多能打捞多少石油(不能石油和海水一起捞)。
先给石油编上号码,编号为:1 2 3 4 5…这种,然后我们遍历这个区域,如果在
因为建立的是双向边,所以要最后结果除以2
代码
#include <bits/stdc++.h>using namespace std;#define mem(a,b) memset(a,b,sizeof(a))const int N=1000+20;int e[N][N],vis[N],match[N],n,temp[N][N],num;char s[N][N];int dfs(int u){ for(int i=1; i<=num; i++) { if(e[u][i]&&!vis[i]) { vis[i]=1; if(!match[i]||dfs(match[i])) { match[i]=u; return 1; } } } return 0;}int query(){ mem(match,0); int sum=0; for(int i=1; i<=num; i++) { mem(vis,0); if(dfs(i))sum++; } return sum;}int main(){ int t,q=1; scanf("%d",&t); while(t--) { mem(temp,0); mem(e,0); num=0; scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%s",s[i]+1); for(int j=1; j<=n; j++) if(s[i][j]=='#') temp[i][j]=++num; } for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(s[i][j]=='#') { if(i!=1&&s[i-1][j]=='#') e[temp[i][j]][temp[i-1][j]]=1; if(j!=1&&s[i][j-1]=='#') e[temp[i][j]][temp[i][j-1]]=1; if(i!=n&&s[i+1][j]=='#') e[temp[i][j]][temp[i+1][j]]=1; if(j!=n&&s[i][j+1]=='#') e[temp[i][j]][temp[i][j+1]]=1; } printf("Case %d: %d\n",q++,query()/2); } return 0;}
- HDU4185 Oil Skimming(二分图匹配,匈牙利算法)
- HDU4185 Oil Skimming-二分匹配
- hdu4185 Oil Skimming(二分匹配)
- hdu4185-Oil Skimming(二分图,模板)
- hdu4185 Oil Skimming (最大匹配)
- hdu4185 Oil Skimming
- HDU4185-Oil Skimming
- Hdu4185 Oil Skimming
- HDU4185 Oil Skimming
- HDU 4185 Oil Skimming 二分图匹配
- hdu 4185 Oil Skimming 二分图匹配
- HDU 4185 Oil Skimming ( 二分匹配建图 )
- HDOJ 4185 - Oil Skimming 离散化后二分图匹配...
- HDU 4185 Oil Skimming(二分图最大匹配)
- HDU 4185 Oil Skimming(离散化 + 二分图匹配)
- HDU 4185 Oil Skimming(二分图最大匹配)
- HDU 4185 Oil Skimming(二分图最大匹配)
- HDU 4185 Oil Skimming && 匈牙利算法
- 整理的关于vim的快捷键大全
- 浅析三种特殊进程:孤儿进程,僵尸进程和守护进程.
- 一些比较好的国外IT网站
- nginx+tomcat 报 504 gateway timeout
- Web监听器导图详解
- HDU4185 Oil Skimming(二分图匹配,匈牙利算法)
- pip更新所有需要更新的包
- 写给Android App开发人员看的Android底层知识
- Pandas DataFrame 函数方法
- 监控系统
- 建设DevOps统一运维监控平台,先从日志监控说起
- Codeforces864D(构造水题?)
- 更新安全补丁后无法读取查询导入Excel问题解决说明书
- CSS实现垂直居中和水平居中