轻量级前端框架助力开发者提升项目效率与性能
586
2022-10-21
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
题目大概:
在一个n*n的矩形中有很多油,一次可以取1*2矩形内的油(且矩形内必须都是油),问最多取几次。
思路:
这个虽然也是矩形问题,矩形中也有东西需要操作,但是却不是用之前的行列为点,焦点为边的建模法。而是,把所有有油的地方标记下来并且重新编号,然后扫一遍矩形找和它相邻的点有油的地方连边,最后跑一遍匈牙利算法,求最大匹配,因为连的是双向边,a扫到b要取,b扫到a也要取,所以答案要/2.。
代码:
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~