HDU:4185-Oil Skimming

Oil Skimming

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)

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

1 6
……
.##…
.##…
….#.
….##
……

Sample Output

Case 1: 3


解題心得:

  1. 題意很簡單,就是要你在圖中去截取1x2的方塊,問最多能截取多少個。
  2. 就是一個二分匹配問題,還是很簡單的,有兩種建圖的方法
    • 第一種是給每一個坐標編號,查找每一個‘#’的四周圖形,然后建一個雙向的圖,得到的答案除2就可以了。
    • 第二種就更高級了,仔細觀察可以觀看一個點的行列之和與他四周的四個格子的行列和奇偶性一定是不同的,這樣就可以參考國際象棋的棋盤,黑色的方格匹配白色方格,二分匹配。

弱智建圖寫代碼:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 610;
char maps[maxn][maxn];
bool vis[maxn*maxn];
vector <int> ve[maxn*maxn];
int n,dir[4][2] = {0,1,0,-1,-1,0,1,0},match[maxn*maxn];void init()
{scanf("%d",&n);for(int i=0;i<maxn;i++)ve[i].clear();memset(vis,0,sizeof(vis));memset(maps,0,sizeof(maps));memset(match,-1,sizeof(match));for(int i=1;i<=n;i++)scanf("%s",maps[i]+1);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(maps[i][j] == '#')for(int k=0;k<4;k++){int x = i + dir[k][0];int y = j + dir[k][1];if(maps[x][y] == '#')ve[i*n+j].push_back(x*n+y);//如果四周是‘#’就建立聯系}}bool dfs(int x)//match
{for(int i=0;i<ve[x].size();i++){int v = ve[x][i];if(!vis[v]){vis[v] = true;if(match[v] == -1 || dfs(match[v])){match[v] = x;return true;}}}return false;
}int solve()
{int ans = 0;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(maps[i][j] == '#'){memset(vis,0,sizeof(vis));if(dfs(i*n+j))ans++;}return ans;
}int main()
{int t;scanf("%d",&t);int cas = 1;while(t--){init();int ans = solve();printf("Case %d: %d\n",cas++,ans/2);//因為建立的是雙向圖,所以一定要除2}return 0;
}

轉載于:https://www.cnblogs.com/GoldenFingers/p/9107219.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/252500.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/252500.shtml
英文地址,請注明出處:http://en.pswp.cn/news/252500.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

域控制器情況分析

域控制器情況分析 1、Windows Server 的 Foundation、Standard、Enterprise 以及 Datacenter 版本號既可作為源server&#xff0c;也可作為目標server。僅支持將 Foundation Server 版本號作為受限方案中的目標server。在使用 Foundation Server 作為目標server之前&#xff0c…

Linux基礎命令---su

su臨時切換身份到另外一個用戶&#xff0c;使用su切換用戶之后&#xff0c;不會改變當前的工作目錄&#xff0c;但是會改變一些環境變量。此命令的適用范圍&#xff1a;RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。1、語法su [選項] [參數]2、選項列表--help顯示…

在Ubuntu 16.04 上安裝和卸載matlab 2018b(Install and uninstall matlab 2018b on ubuntu)

1.安裝2018b可以參考下面兩篇文章 https://www.ph0en1x.space/2018/04/23/ubuntu_matlab/ https://blog.csdn.net/qq_32892383/article/details/79670871 2.卸載2018b 我的默認安裝在 /usr/local/MATLAB $ sudo rm -r /usr/local/MATLAB $ cd ~ $ ll (這個時候可以看到隱…

04.openssl編程——哈希表

4.1 哈希表在一般的數據結構如線性表和樹中&#xff0c;記錄在結構中的相對位置與記錄的關鍵字之間不存在確定的關系&#xff0c;在結構中查找記錄時需要進行一系列的關鍵字比較。這一類查找方法建立在比較的基礎上&#xff0c;查找的效率與比較次數密切相關。理想的情況是能…

shell數組中“和@的妙用

#!/bin/bashlist(4k"8k a bit""16k abc""32k gold"64k)for i in "${list[]}"do echo $idone 分別對比一下不帶” 和換成*&#xff0c;之間的區別。轉載于:https://www.cnblogs.com/zjd2626/p/7041341.html

「JupyterLab」 Jupyter Notebook 新生代IDE模式頁面

參考&#xff1a;Overview 安裝&#xff1a; $ pip install jupyterlab 啟動&#xff08;不是jupyter notebook&#xff09;&#xff1a; $ jupyter lab Jupyterlab中最好用的就是顯示csv數據。CSV數據顯示效果&#xff1a; 安裝插件 jupyterlab是和jupyter notebook隔離的&…

undefined reference to 'pthread_create'

剛在Ubuntu16.04 上用Clion寫一個"單生產者-單消費者"的線程的程序&#xff0c;源程序可以參考下面的網址 https://www.cnblogs.com/haippy/p/3252092.html 在編譯的時候編譯器給的提示是&#xff1a; undefined reference to pthread_create 解決辦法就是在CMake…

windows下安裝vundle

windows下安裝vundle ## 前言 windows下安裝vundle和linux下稍微有些不一樣&#xff0c;雖然官網給出了 安裝說明&#xff0c;但是有些問題的。E117: Unknown function: vundle#begin ## 安裝步驟 參考官方文檔即可vundle ## 問題處理 修改_vimrc配置文件內容&#xff0c;這是正…

深度學習框架不能“包治百病”,開發者如何選出最適合自己的?

隨著深度學習關注度和勢頭上升&#xff0c;深度學習被越來越多的企業和組織的生產實踐結合起來。這時&#xff0c;無論是對于深度學習相關專業的初學者&#xff0c;還是已經在企業和組織中從事工業場景應用和研發的開發者來說&#xff0c;選擇一個適合自己&#xff0c;適合業務…

Linux+CLion+cmake 動態鏈接庫的使用

在作《劍指offer》中的單向鏈表的題目時&#xff0c;需要一些常用到的操作鏈表的函數放在一個文件下&#xff0c;我想把這些函數的聲明都寫在list.h文件中&#xff0c;把這些函數的定義都寫在list.cpp文件中&#xff0c;這樣就可以在測試文件test.cpp中調用list.cpp中定義的函數…

PAT(乙級)1009

1009. 說反話 (20)給定一句英語&#xff0c;要求你編寫程序&#xff0c;將句中所有單詞的順序顛倒輸出。 輸入格式&#xff1a;測試輸入包含一個測試用例&#xff0c;在一行內給出總長度不超過80的字符串。字符串由若干單詞和若干空格組成&#xff0c;其中單詞是由英文字母&…

庫存扣減問題

2019獨角獸企業重金招聘Python工程師標準>>> 并發減庫存 并發扣庫存問題總結 庫存扣減還有這么多方案&#xff1f; | 架構師之路 轉載于:https://my.oschina.net/u/2939155/blog/3004363

HSRPSTPACL

1 HSRP配置 1.1 問題 在企業網絡到外部的連接方案中&#xff0c;要求不高的條件下可以是單出口。一旦該出口線路出現問題&#xff0c;整個企業網絡就不能連接到外網了。為了使得企業網絡到外網連接的高可用性&#xff0c;可以設置兩個以上的出口&#xff0c;然而多個出口對…

java 的 CopyOnWriteArrayList類

初識CopyOnWriteArrayList 第一次見到CopyOnWriteArrayList&#xff0c;是在研究JDBC的時候&#xff0c;每一個數據庫的Driver都是維護在一個CopyOnWriteArrayList中的&#xff0c;為了證明這一點&#xff0c;貼兩段代碼&#xff0c;第一段在com.mysql.jdbc.Driver下&#xff0…

科技的趨勢!AI將進軍了37%的企業

2019獨角獸企業重金招聘Python工程師標準>>> 市場研究機構Gartner調查了全球89個國家的逾3,000名信息長&#xff08;CIO&#xff09;&#xff0c;顯示有37%的企業已經或打算于近期內部署人工智能&#xff08;AI&#xff09;&#xff0c;在4年內成長270%。Gartner研究…

CMakeLists.txt編寫規則

在PROJECT_SOURCE_DIR下新建了src, include, lib, bin四個子文件夾。 src文件夾用來存放所有的.cpp文件&#xff0c;include文件夾用來存儲所有的.h文件&#xff0c; lib中存放生成的自己編寫的共享庫&#xff0c; bin中存放所有的可執行文件 用SET來設置.exe可執行文件和共享…

nginx.conf配置詳解

######Nginx配置文件nginx.conf中文詳解######定義Nginx運行的用戶和用戶組 user www www;#nginx進程數&#xff0c;建議設置為等于CPU總核心數。 worker_processes 8;#全局錯誤日志定義類型&#xff0c;[ debug | info | notice | warn | error | crit ] error_log /usr/local…

更新 hadoop eclipse 插件

卸載hadoop 1.1.2插件。并安裝新版hadoop 2.2.0插件。 假設直接刪除eclipse plugin文件夾下的hadoop 1.1.2插件&#xff0c;會導致hadoop 1.1.2插件殘留在eclipse中&#xff0c;在eclipse perspective視圖中有Map/Reduce視圖&#xff0c;可是沒有圖標&#xff0c;新建項目也不會…

【K8S學習筆記】Part1:使用端口轉發訪問集群內的應用

本文介紹如何使用kubectl port-forward命令連接K8S集群中運行的Redis服務。這種連接方式有助于數據庫的調試工作。 注意&#xff1a;本文針對K8S的版本號為v1.9&#xff0c;其他版本可能會有少許不同。 0x00 準備工作 在進行該操作之前&#xff0c;需要滿足以下條件&#xff1a…

Ubuntu 16.04 桌面菜單欄 任務欄 標題欄消失的解決辦法

將home目錄下的.cache刪除掉就可以了 & cd & sudo rm -r ./.cache