Hdu4185 Oil Skimming
来源:互联网 发布:java 清华 pdf 编辑:程序博客网 时间:2024/05/21 17:27
Oil Skimming
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
Source
The 2011 South Pacific Programming Contest
Recommend
lcy | We have carefully selected several similar problems for you: 4186 4177 4178 4180 4181
————————————————————————————————————
题目的意思是给出一张图#表示油田,用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 longconst 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;}
阅读全文
0 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(二分图匹配,匈牙利算法)
- Oil Skimming
- hdu 4185 Oil Skimming
- Oil Skimming HDU
- Oil Skimming HDU
- Oil Skimming HDU
- Oil Skimming HDU
- Oil Skimming(二分图)
- HDU 4185Oil Skimming 匈牙利
- hdu 4185Oil Skimming (二分匹配)
- 搭建springmvc环境的步骤(基于注解)
- Hdu2819 Swap
- PHP 高级编程之 消息队列
- (笔记)Android调用相机,并接收图片
- 搭建springmvc环境的步骤(基于配置文件)
- Hdu4185 Oil Skimming
- Mysql中大小写敏感问题
- c#匿名方法调用委托
- SpringBoot 处理静态资源
- 用数组和链表两种方式实现栈
- 基于magic_quotes_gpc与magic_quotes_runtime的区别与使用介绍
- PYTHO 爬虫,抓去京东产品价格DEMO
- 20170629总结
- 快速排序非递归java