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/ ...
随机推荐
- 【C++】《C++ Primer 》第十三章
第十三章 拷贝控制 定义一个类时,需要显式或隐式地指定在此类型地对象拷贝.移动.赋值和销毁时做什么. 一个类通过定义五种特殊的成员函数来控制这些操作.即拷贝构造函数(copy constructor) ...
- python中列表的insert和append的效率对比
python中insert和append方法都可以向列表中插入数据只不过append默认插入列表的末尾,insert可以指定位置插入元素. 我们来测试一下他俩插入数据的效率: 测试同时对一个列表进行插 ...
- 【Linux】快速创建文件的命令方法
[root@centos7 dir1]# ll total 0 -rw-r--r-- 1 root root 0 Aug 15 02:39 file1 -rw-r--r-- 1 root root 0 ...
- 【Oracle】整库导出后怎么恢复到指定用户的指定表
在导出的时候,整库导出 这里使用的是dba权限 $exp "'/ as sysdba'" file=full20180227.dmp log=exp_full20180227.lo ...
- Python利用最优化算法求解投资内部收益率IRR【一】
一. 内部收益率和净现值 内部收益率(Internal Rate of Return, IRR)其实要和净现值(Net Present Value, NPV)结合起来讲.净现值指的是某个投资项目给公司 ...
- Pytorch入门——手把手教你MNIST手写数字识别
MNIST手写数字识别教程 要开始带组内的小朋友了,特意出一个Pytorch教程来指导一下 [!] 这里是实战教程,默认读者已经学会了部分深度学习原理,若有不懂的地方可以先停下来查查资料 目录 MNI ...
- 给dtcms增加模板自动生成功能
作为dtcms的使用者你是不是像我一样,也在不停的修改模板之后要点击生成模板浪费了很多开发模板的时间? 那就跟我一起给dtcms增加一个开发者模式,当模板修改完成之后,直接刷新页面就能看到效果,而不再 ...
- nodejs内网穿透
说明 本地服务注册,基于子域名->端口映射.公网测试请开启二级或三级域名泛解析 无心跳保活.无多线程并发处理 服务器端 请求ID基于全局变量,不支持PM2多进程开服务端.(多开请修改uid函数, ...
- 2V转3V的电源芯片电路图,2.4V转3V电路
两节镍氢电池1.2V+1.2V是2.4V的标称电压,2.4V可以转3V输出电路应用. 在2.4V转3V和2V转3V的应用中,输出电流可最大600MA. 2V的低压输入,可以采用PW5100低压输入专用 ...
- 好你个C语言,原来还有这么多副面孔!
C语言可以这样比喻,是一门非常强大的内功心法,学会它可以做到一法通万法.这也是它至今不衰的原因.说了这么多C语言的优点,现在来说说它的缺点.C语言最大的优点也是它最大的缺点,拥有强大的力量时应时刻保持 ...