hdu 4185 二分图最大匹配
Oil Skimming
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1487 Accepted Submission(s): 612
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 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.
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.
6
......
.##...
.##...
....#.
....##
......
- #include<stdio.h>
- #include<string.h>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- const int maxn = ;
- const int INF = ;
- bool vis[maxn];
- int link[maxn];
- int G[maxn][maxn];
- int x_cnt;
- int y_cnt;
- int temp[maxn][maxn];
- char str[maxn][maxn];
- bool find(int u)
- {
- for(int i = ; i <= y_cnt; i++)
- {
- if(!vis[i] && G[u][i])
- {
- vis[i] = true;
- if(link[i] == - || find(link[i]))
- {
- link[i] = u;
- return true;
- }
- }
- }
- return false;
- }
- int solve()
- {
- int num = ;
- memset(link, -, sizeof(link));
- for(int i = ; i <= x_cnt; i++)
- {
- memset(vis, false, sizeof(vis));
- if(find(i))
- num++;
- }
- return num;
- }
- int main()
- {
- int t,cnt=;
- scanf("%d",&t);
- while(t--){
- cnt++;
- int n;
- scanf("%d",&n);
- int tmp=;
- memset(temp,,sizeof(temp));
- memset(G,,sizeof(G));
- memset(str,,sizeof(str));
- for(int i=;i<n;i++)
- {
- scanf("%s",&str[i]);
- for(int j=;j<n;j++)
- if(str[i][j]=='#')
- temp[i][j]=++tmp;
- }
- x_cnt=tmp, y_cnt=tmp;
- for(int i=;i<n;i++)
- for(int j=;j<n;j++)
- {
- if(str[i][j]!='#') continue;
- if(i>&&str[i-][j]=='#') G[temp[i][j]][temp[i-][j]]=;
- if(i<n-&&str[i+][j]=='#') G[temp[i][j]][temp[i+][j]]=;
- if(j>&&str[i][j-]=='#') G[temp[i][j]][temp[i][j-]]=;
- if(j<n-&&str[i][j+]=='#') G[temp[i][j]][temp[i][j+]]=;
- }
- printf("Case %d: %d\n",cnt,solve()/);
- }
- return ;
- }
hdu 4185 二分图最大匹配的更多相关文章
- hdu 1281 二分图最大匹配
对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1 Y1 X2 Y2 X3 Y3 ..... Xn Yn ...
- HDU - 2444 二分图最大匹配 之 判断二分图+匈牙利算法
题意:第一行给出数字n个学生,m条关系,关系表示a与b认识,判断给定数据是否可以构成二分图,如果可以,要两个互相认识的人住一个房间,问最大匹配数(也就是房间需要的最小数量) 思路:要看是否可以构成二分 ...
- hdu 4185 二分图匹配
题意用1*2的木板覆盖矩阵中的‘#’,(木板要覆盖的只能是‘#’),问最多能用几个木板覆盖 将#抽象为二分图的点,一个木板就是一个匹配,注意最后结果要除以2 Sample Input 1 6 .... ...
- hdu 4619 二分图最大匹配 ——最大独立集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 #include <cstdio> #include <cmath> # ...
- HDU 3279 二分图最大匹配
DES: 就是说对每个人都给你一个区间.但一个人只匹配一个数.问你满足匹配的人的序号字典序最大时的最大匹配是什么. 前几天刚做的UVALive 6322...当然是不一样的...那个要求的最大匹配的个 ...
- hdu 3729(二分图最大匹配)
I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU:过山车(二分图最大匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2063 题意:有m个男,n个女,和 k 条边,求有多少对男女可以搭配. 思路:裸的二分图最大匹配,匈牙利算法. 枚 ...
- [HDU] 2063 过山车(二分图最大匹配)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063 女生为X集合,男生为Y集合,求二分图最大匹配数即可. #include<cstdio> ...
- HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配)
HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配) Description The zoo have N cats and M dogs, toda ...
随机推荐
- 最简单的基于FFMPEG的转码程序 —— 分析
模块: libavcodec - 编码解码器 libavdevice - 输入输出设备的支持 libavfilter - 视音频滤镜支持 ...
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer
这其实就是 获得应用的根url,比如说你的应用的根路径是 http://localhost:8080,那么你列出的代码就是为basePath赋值为 http://localhost:8080.具体点: ...
- ReentrantReadWriteLock的使用
ReentrantReadWriteLock的规则是: 多线程情况下:读-写互斥.写-读互斥.写-写互斥.读-读共享 验证“读-写互斥.写-读互斥.写-写互斥.读-读共享” //单个线程 读-读 不互 ...
- 【转】转自微信公众号 JavaScript 复杂判断的更优雅写法
与微信公众号看到一篇js复杂判断的文章,对我启发很大,故转到博客园以供后期不断学习并应用于项目.原文地址:https://mp.weixin.qq.com/s/ClFDRj4MnAxv1dJ5VWKS ...
- 区块链工作 jd
https://www.lagou.com/jobs/4096098.html 技术咨询网站: https://mp.weixin.qq.com/s/hs37UZFGI3uR4qmQ7v346g## ...
- windows2012服务器搭建mongodb并设置远程访问
因为python脚本需要用到mongodb,而且需要本地查看数据库,所以就在腾讯云的windows服务器上部署了mongodb服务器,因为网上大部分教程是针对linux的自己搜索走了很多坑,这里记录下 ...
- 1412: [ZJOI2009]狼和羊的故事
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4017 Solved: 2037[Submit][Status][Discuss] Descript ...
- content is king – Bill Gates (1/3/1996) 内容为王 - 比尔盖茨
以下中文版本由谷歌翻译 内容为王 - 比尔盖茨(1/3/1996) 内容是我期望在互联网上赚取大部分真钱的地方,就像在广播中一样. 半个世纪前开始的电视革命催生了许多行业,包括制造电视机,但长期的赢家 ...
- css3 横向拖拽
css: .tab{ list-style-type: none; display:-webkit-box; display:-webkit-flex; ...
- Python中的bytes
bytes_lst = [ ('创建bytes',), ('bytes可哈希',), ('编码与解码',), ('常见编码类型',), ('ord() 与 chr()',), ] 创建bytes &g ...