1. 程式人生 > >HDU 1045 Fire Net 最大二分圖匹配

HDU 1045 Fire Net 最大二分圖匹配

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. 

A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening. 

Here we assume that a bullet is so powerful that it can run across any distance and destroy a blockhouse on its way. On the other hand, a wall is so strongly built that can stop the bullets. 

The goal is to place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map unless there is at least one wall separating them. In this problem we will consider small square cities (at most 4x4) that contain walls through which bullets cannot run through. 

The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of blockhouses in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways. 



Your task is to write a program that, given a description of a map, calculates the maximum number of blockhouses that can be placed in the city in a legal configuration. 

相關推薦

HDU 1045 Fire Net 二分匹配

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a pie

二分匹配的C++程式碼實現

    最大二分圖匹配是典型的圖論問題,一般有兩種做法,一種是運用最大流的思想,不過這種方法效率太低,為O(VE^2),沒有利用好二分圖的特殊性質。另一種做法是匈牙利 演算法,這種方法也是利用了增益路徑的思想,但這種方法充分利用了二分圖的性質,所以效率也是比較高的,為O(V

1150 Machine Schedule 小點覆蓋(二分匹配-匈牙利演算法)鄰接表寫法

日! 最近 CF 做的多了,再做多組輸入的題的時候 忘記陣列清空,,然後wa了 好久。。。 我就說嗎。。。這麼裸的匈牙利怎麼會出錯呢? ——————————————————————分割 這個題是最小點覆蓋問題,畫出圖來以後可以知道是找最少的點覆蓋所有邊,每個點覆蓋它相連的邊

HDU 1045 Fire Net (二分匹配)

/* 構圖:對於任意一行,如果該行裡的格子彼此可到達(沒有障礙物),則把他們歸為同一個 點,縱向也是如此。 構造出來的橫向點和縱向點,如果彼此覆蓋,則連一條邊,最後直接 求最大匹配。 15MS 312K */ #include <iostream&g

HDU 1045 Fire Net 二分匹配

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piec

HDU 1045 Fire Net二分匹配

#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<

hdu 1045 Fire Net二分匹配

進行 col numbers res clu 意思 archive 多少 color <題目鏈接> <轉載於 >>> > 題目大意: 這題意思是給出一張圖,圖中‘X‘表示wall,‘.‘表示空地,可以放置炮臺,同一條直線上只

HDU 1045 Fire Net 【連通塊的壓縮 二分匹配

題目:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav

HDU 1045 Fire Net 二分

HDU 1045 題意:   在一個n*n地圖中,有許多可以擋住子彈的牆,問最多可以放幾個炮臺,是的炮臺不會相互損害。炮臺會向四面發射子彈。 思路:   把行列分開做,先處理行,把同一行中相互聯通的點縮成一個點。再處理列,同樣縮成一個點。然後把行列中,交點不是牆的點連一條邊。對這個圖跑網路流或者二分圖

HDU 1045 Fire Net 詳細題解(二分經典模型)

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a pie

HDU 1045 Fire Net 二分Bipartite題解

本題可以使用DFS直接爆搜出答案,不過這樣型別的題目其實是個二分圖的題解。 這個二分圖,難不在Hungary演算法,而是難在於建圖。需要挺高的抽象思維的。 建圖: 1 把同一行不被X分開的格子標同一個號碼,被X分開的標下一個號碼,這樣做是為了縮點,不需要把所有的格子都分開標

HDU 1045 Fire Net(建模,用二分匹配

參考kuangbin教主的解法,連結http://www.cnblogs.com/kuangbin/archive/2011/08/09/2132830.html。 但是感覺他的建模有點問題. Suppose that we have a square city with

HDU 1045 fire net二分匹配或者DFS】

#include<stdio.h> #include<string.h> char map[5][5]; int mapr[5][5],mapl[5][5]; int g[20][20];/*儲存邊的資訊*/ int link[20],use[20]; int uN,vN; int a

HDU-1045,Fire Net-純暴力簡單DFS】

n! closed 實現 problem 由於 gif open pan alt 原題鏈接:點擊! 大致題意:白塊表示可以放置炮臺的位置——每個炮臺可以攻擊到上下左右的直線上的炮臺(也就是說在它的上下左右直線上不可以再放置炮臺,避免引起互相攻擊),黑塊表示隔離墻的位置

HDU 1045 Fire Net

題目連結:傳送門 Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and

HDU-1045 Fire Net

可以直接dfs暴搜,也可以轉化為二分圖匹配問題 每一行連續的片段可以縮為一個點,列上連續的片段也是,因為連續的片段最多放一個點 就分為行片段,列片段兩部分,他們的交點就是邊,求最大匹配就是最多可以放的點 dfs暴搜程式碼: #include<iostream&g

HDU 1045 Fire Net(搜尋剪枝)

http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 題目連結(總有一個可以點開)…… 題意:給出一張地圖,上面只有兩種字元(.和X),X相當於無法穿透的牆。問這張地圖上最多可以放置多少個互不攻擊的子彈…… 第一反應是

hdu 1045 Fire Net(回溯搜尋)

搜尋,回溯!!!人的一生避免不了會犯一些小錯誤!!! 那麼犯錯錯誤可以回頭的!不可以一直錯下去的!!! #include<stdio.h> #include<string.h> int visit[10][10]; char map[10][10];

bzoj2539 丘比特的煩惱、黑書P333 (二分匹配

def 等於 ostream while 感情 deb valentine 區分 匹配 丘比特的煩惱 題目描述 Description   隨著社會的不斷發展,人與人之間的感情越來越功利化。最近,愛神丘比特發現,愛情也已不再是完全純潔的了。這使得丘比特很是苦惱,

HDU 5727 Necklace(全排列+二分匹配

color algorithm target () mark ++ int turn open http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 題意:現在有n個陽珠子和n個陰珠子,現在要把它們串成項鏈,要求是陰陽珠