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,且付出的代价之和最小,并输出方案. 如果有多种方案,请输出将删去项的附加属性排序 ...
随机推荐
- Centos6.5
1.首先我们需要检测系统是否自带安装mysql # yum list installed | grep mysql 2.如果发现有系统自带mysql,果断这么干 # yum -y remove mys ...
- Python 3基础教程31-urllib模块
本文介绍Python里的urllib模块,这个urllib主要处理web服务的,如果需要做接口测试,或者写Python的网络爬虫,这个urllib就是最底层的库.需要用到里面的请求方法等. 1. 先看 ...
- Halcon环境搭建
1.Visual Studio 2017安装教程 2.Qt5.9安装教程 3.VS2017中Qt插件安装教程
- UVa 294 - Divisors 解题报告 c语言实现 素数筛法
1.题目大意: 输入两个整数L.H其中($1≤L≤H≤10^9,H−L≤10000$),统计[L,H]区间上正约数最多的那个数P(如有多个,取最小值)以及P的正约数的个数D. 2.原理: 对于任意的一 ...
- 山科 STUST OJ Problem B: 编写函数:String to Double (II) (Append Code)
这道题没啥别的毛病,我的错误在于看不懂题. 另外还有一点是注意浮点数存在-0 #include <stdio.h> #include <ctype.h> #include &l ...
- jquery在页面加载完成后再append的元素事件无效问题
最近遇到一个问题,jquery在页面加载完成后再append的元素,append元素上有onclick事件,但是在append的元素上怎么点击都不会触发onclick事件.就如: <ul cla ...
- 有关parent.frame.cols在firefox浏览器上不兼容的问题解决
IE(不兼容FireFox): if(parent.myFrame.cols == "199,7,*") { parent.myFrame.cols="0,7,*&quo ...
- java连接mysql底层封装
package com.dao.db; import java.sql.Connection; import java.sql.SQLException; /** * 数据库连接层MYSQL * @a ...
- jetty-maven-plugin
<plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifact ...
- 【PHP】- session_cache_limiter(private,must-revalidate)是什么意思
session_cache_limiter(private,must-revalidate)是什么意思 表义一: 指定会话页面所使用的缓冲控制方法: 当session_cache_limiter('p ...