HDU1045(二分图经典建模)
Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8338 Accepted Submission(s): 4796
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.
/*
ID: LinKArftc
PROG: 1045.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const double e = exp(1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ; struct Node {
char cha;
int idx, idy;
} node[maxn][maxn];
int mp[maxn][maxn];
int n, uN, vN;
int linker[maxn];
bool vis[maxn]; bool dfs(int u) {
for (int v = ; v <= vN; v ++) {
if (!vis[v] && mp[u][v]) {
vis[v] = true;
if (linker[v] == - || dfs(linker[v])) {
linker[v] = u;
return true;
}
}
}
return false;
} int hungry() {
memset(linker, -, sizeof(linker));
int ret = ;
for (int i = ; i <= uN; i ++) {
memset(vis, , sizeof(vis));
if (dfs(i)) ret ++;
}
return ret;
} int main() { while (~scanf("%d", &n) && n) {
for (int i = ; i <= n; i ++) {
for (int j = ; j <= n; j ++) scanf(" %c", &node[i][j].cha);
}
uN = ;
for (int i = ; i <= n; i ++) {
for (int j = ; j <= n; j ++) {
if (node[i][j].cha == 'X') continue;
if (j == && node[i][j].cha == '.') uN ++;
else if (node[i][j].cha == '.' && node[i][j-].cha == 'X') uN ++;
node[i][j].idx = uN;
}
}
vN = ;
for (int j = ; j <= n; j ++) {
for (int i = ; i <= n; i ++) {
if (node[i][j].cha == 'X') continue;
if (i == && node[i][j].cha == '.') vN ++;
else if (node[i][j].cha == '.' &&node[i-][j].cha == 'X') vN ++;
node[i][j].idy = vN;
}
}
memset(mp, , sizeof(mp));
for (int i = ; i <= n; i ++) {
for (int j = ; j <= n; j ++) {
if (node[i][j].cha == 'X') continue;
mp[node[i][j].idx][node[i][j].idy] = ;
}
}
printf("%d\n", hungry());
} return ;
}
HDU1045(二分图经典建模)的更多相关文章
- hdoj--5093--Battle ships(二分图经典建图)
Battle ships Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- poj1149 经典建模
http://wenku.baidu.com/view/0ad00abec77da26925c5b01c.html 以上内容均为转载 #include<queue> #include< ...
- Wolsey“强整数规划模型”经典案例之一单源固定费用网络流问题
Wolsey“强整数规划模型”经典案例之一单源固定费用网络流问题 阅读本文可以理解什么是“强”整数规划模型. 单源固定费用网络流问题见文献[1]第13.4.1节(p229-231),是"强整 ...
- 的二分图poj2446
称号:id=2446">poj2446 意甲冠军:给定一个m*n矩阵,在有些地方坑,然后1*2本文叠加,反复.可以把出了坑的地方其它所有覆盖的话输出YES,否则NO 分析:有一道二分图 ...
- 「国庆训练&知识学习」图的最大独立集与拓展(Land of Farms,HDU-5556)
题意 一个\(N*M\)的矩阵,其中"."代表空地,"0-9"代表古代建筑,我们如果选择了一个编号的古代建筑想要建立,那么对应就要将全部该编号的建筑建立起来,如 ...
- JZOJ 5934. 列队
Description Sylvia是一个热爱学习的女孩子. 在平时的练习中,他总是能考到std以上的成绩,前段时间,他参加了一场练习赛,众所周知,机房是一个 的方阵.这 ...
- 【bzoj1976】[BeiJing2010组队]能量魔方 Cube 网络流最小割
题目描述 一个n*n*n的立方体,每个位置为0或1.有些位置已经确定,还有一些需要待填入.问最后可以得到的 相邻且填入的数不同的点对 的数目最大. 输入 第一行包含一个数N,表示魔方的大小. 接下来 ...
- 网络流24题:P2762 太空飞行计划问题
P2762 太空飞行计划问题 题目背景 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,E ...
- BZOJ3532 [Sdoi2014]Lis 【网络流退流】
题目 给定序列A,序列中的每一项Ai有删除代价Bi和附加属性Ci.请删除若 干项,使得4的最长上升子序列长度减少至少1,且付出的代价之和最小,并输出方案. 如果有多种方案,请输出将删去项的附加属性排序 ...
随机推荐
- Android Spiner实现Key-Value
原网址:http://www.eoeandroid.com/thread-29687-1-1.html?_dsign=02d5cd6a 学习到的方法,直接上代码了: 1.定义一个class publi ...
- 第一周 Introduction
欢迎 欢迎来到这门关于机器学习的免费网络课程,机器学习是近年来最激动人心的技术之一,在这门课中,你不仅可以了解机器学习的原理,更有机会进行实践操作,并且亲自运用所学的算法. 每天你都可能在不知不觉中使 ...
- JAVA课程设计——植物大战僵尸(团队)
1.团队名称.团队成员介绍 团名:嗷嗷嗷嗷嗷 吴军霖(组长) 写得一手好代码也改得一手好bug 代码整洁好看源于强迫症 大概没有什么不会的东西叭 真正的王者段位 欧阳震霆(组员) 同样擅长写代码 在青 ...
- Spring MVC温故而知新 – 参数绑定、转发与重定向、异常处理、拦截器
请求参数绑定 当用户发送请求时,根据Spring MVC的请求处理流程,前端控制器会请求处理器映射器返回一个处理器,然后请求处理器适配器之心相应的处理器,此时处理器映射器会调用Spring Mvc 提 ...
- PhoneGap & HTML5 学习资料网址
PhoneGap 与 Application Cache应用缓存 http://www.html5cn.org/forum.php?mod=viewthread&tid=40272 加速We ...
- PHPExcel 导出包含图片excel
<?php // 这里用的PHPExcel版本号为1.8.0 // 下载地址https://github.com/PHPOffice/PHPExcel 下载ZIP压缩包 // 下载后将Class ...
- 【UML】活动图介绍
1.活动图,即Activity Diagram,是UML中用于对系统的动态行为建模的一种常用工具,它描述活动的顺序,展现从一种活动到另一种活动的控制流.其本质上是一种流程图,着重表现从一个活动到另一个 ...
- Aspose.Pdf合并PDF文件
使用Aspose.Pdf类库,有很多种方法可以合并PDF文件,这里简单介绍小生见到的几种: Doucment.Pages.Add PdfFileEditor.Append PdfFileEditor. ...
- log4j的常用使用方法
第一步,引入jar包,不做介绍. 第二步,创建以下类(固定写法) package smn.util; import org.apache.log4j.Logger; public class MyLo ...
- LeetCode -- Linked List Circle ii
Question: Given a linked list, return the node where the cycle begins. If there is no cycle, return ...