hdu 5093 Battle ships (二分图)】的更多相关文章

题意:一个m行n列的图由#.*.o三种符号组成,分别代表冰山.海域.浮冰,问最多可放的炮舰数(要求满足以下条件) 1.炮舰只可放在海域处 2.两个炮舰不能放在同一行或同一列(除非中间隔着一个或多个冰山) 分析: 1.如果单纯只考虑不能放在同一行同一列,那就是行号与列号的匹配,原理与UVALive 6811 Irrigation Line(二分图最小点覆盖--匈牙利算法)相同. 2.但现在隔着冰山可以放置炮舰,那假设某一行被冰山分隔成两部分,这一行的前半部分和后半部分可以看做是两行,再应用"行号&…
二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ooo* ooo* 再按列展开... 7 * 8 *ooooooo oooooooo oooooooo oooooooo *o*ooooo ooooooo* ooooooo* 匹配结果3 Battle ships Time Limit: 2000/1000 MS (Java/Others)    M…
二分图最大匹配问题 遇到冰山就把行列拆成两个部分.每个部分x也好,y也好只能匹配一次 图画得比较草,将就着看 横着扫一遍,竖着扫一遍,得到编号 一个位置就对应一个(xi,yi)就是X集到Y集的一条边, 由题意,每个点只能被选择一次.所以最大匹配的边数就是答案了. 算法过程 当增广路不存在的时候,就是二分图最大匹配.(同样适用其他任意图,可以求最大流) 通常都是先贪心求一个匹配,然后开始增广. 寻找增广路的过程: 一个没有和任意边匹配的点叫做未盖点,从左集X中一个未盖点u出发寻找增广路. 从u出发…
题意: M*N的矩阵,每个格子上是三个之一:*.o.#.                     (1 <= m, n <= 50) *:海洋,战船可以停在上面.      o:浮冰,战船不可以停在上面      #:冰山,战船不可以停在上面. 限制:两艘战船不能处于同一行或同一列,除非它们之间有冰山挡着. 问最多可以停多少艘战船. 思路: 和二分图最小点覆盖那道经典题很相似.不过不是求最小点覆盖. 对于每一行,如果连续的一段只能放一艘战船,则将这一段视为同一个点.则每一行都被分为若干个小段,…
二分图匹配 #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #define maxn 60 #define maxd 1500 using namespace std; int v[maxd][maxd],vist[maxd],math[maxd]; int col[maxn][maxn],row[maxn][maxn]; int k1,k2,n,m; char st…
//这题逼我把匈牙利学了 之前一直很勤快敲网络流 而且不以为耻反以为荣 解:首先按行扫描编号,如果在同一块中(即可以相互攻击),那么将其标为相同的数组,对列也做同样的操作. 然后扫描整张图,如果行编号为a的块与列编号为b的块有公共点,那么将二部图中A集合中a点与B集合中b点相连.最后求出来最大二分匹配数就是答案. (为什么这样做)首先很明显的,二部图中每一条边就对应原图中的一个点,因此,匹配数=边数=最多可放置的战舰数,另外二分图每个点只能匹配一次,对应到原题中就是每一块只能放置一个战舰. #i…
题目:pid=5093" target="_blank">hdoj 5093 Battle ships 题意:给你一个n*m的图,图中有冰山 '# ',浮冰 'o' 以及普通海 ' * ',如今要在海中布置尽可能多的炮弹.炮弹不能突波冰山,不能让炮弹互相攻击到.问最大能不知多少个? 分析:二分图的经典题目.关键在于怎么建图,图进行两次编号,按行编号,每一行中能攻击到的一块编号成相同的数,每一列相同.然后对行和列有编号的地方进行连边,求一次最大匹配就可以,我用最大流求的最…
Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1007    Accepted Submission(s): 353 Problem Description Dear contestant, now you are an excellent navy commander, who is responsible…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1091    Accepted Submission(s): 395 Problem Description Dear contestant, now you are an excellent navy commander, who is responsible of a tough mi…
http://acm.hdu.edu.cn/showproblem.php?pid=5093 给定一个MxN大小的图,有3种点,冰山.浮冰.海.现在希望能在图中放置尽可能多的船.船的四个方向上不能有其他的船,除非有冰山阻隔. 最自然的想到搜索,但是由于矩阵大小有50^2,显然会超时 其实可以将一行被冰山隔开且包含海水的连续区域叫做"块". 把每个横向"块"看做二部图中的X中的顶点,竖向"块"看做集合中Y的顶点,若两个"块"有公…
每个海面要么放要么不放,因此可以用二分图匹配, 考虑把同一行内的能互相看到的点放到一个行块里,同一列内能看到的点放到一个列块里,然后每一个行块都可以和该行块里所有海面的列块连边,选了这个行块,就必须选且只选择一个该行块里的一个海面对应的列块. #include <iostream> #include <cmath> #include <cstdio> #include <algorithm> #include <cstring> #define…
传送门 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line con…
D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/problem/D Description Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n s…
Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is responsible of a tough mission currently.Your fleet unfortunately encountered an enemy fleet near the South Pole where the geographical conditions are ne…
D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/problem/D Description Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n …
Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N ki…
D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consist…
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes tiseconds to produce the…
B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3623 Appoint description:   Description Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a…
传送门Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N…
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes ti seconds to produce th…
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positio…
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : standard output Problem Description Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting…
Battle shipsHDU - 5093 题目大意:n*m的地图,*代表海洋,#代表冰山,o代表浮冰,海洋上可以放置船舰,但是每一行每一列只能有一个船舰(类似象棋的車),除非同行或者同列的船舰中间有冰山挡着,问最多能放多少个船舰? 之前做过一个放置炮的,那时数据小直接暴力加搜索就A了,然而这题暴力搜索的话,直接了当的TLE,没办法只好去学新东西了.二分图这个概念只有在之前的题目中做过匈牙利的板子题,可是具体概念和思路并不了解,这题也正好提醒了我去深入了解.但最近需要做的事情较大,一直想整理的…
http://acm.hdu.edu.cn/showproblem.php?pid=5093 二分图最大匹配的经典建图模型,行列分别缩点(连起来的'*' & 'o'),交集有'*'就连边 #include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <algorithm> using namespace std; struct node…
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #include<cstdio> #include<cstring> #define maxm 410 using namespace std; int p,n; int master[maxm]; int linking[maxm][maxm]; int has[maxm]; int sol…
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid…
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7469   Accepted: 4451 Description Consider a town where all the streets are one-way and each street leads from one intersection to an…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个模式完成. 两个机器初始都是0模式,一个机器转换一个模式需要重启一次.问你最少需要重启几次能完成所有的任务. 不太明显的二分匹配,将每个任务的两个模式连线,大概就能看出来这是个最小点覆盖问题. /* 将下面任务的a状态和b状态连边,线的个数就是任务个数. 要使重启次数最少,那么就要使选择的点最少而且…
[题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5727 [题目大意] 现在有n颗阴珠子和n颗阳珠子,将它们阴阳相间圆排列构成一个环,已知有些阴珠子和阳珠子不能放在相邻的位置,否则这颗阳珠子就会失去功效,输出最少失去能量的阳珠子数目 [题解] 对于阴珠子固定的排列方式,可以用算出阳珠子能够不失去能量就能够放置的位置,将这种关系看成一条边,进行二分图匹配,就可以得不失去能量的阳珠子的最大值,显然就可以获得最少失去能量的数目. 注意在此题中,不知道阴珠…