/*************************************************************************
> File Name: hdu-4185.oil_skimming.cpp
> Author: CruelKing
> Mail: 2016586625@qq.com
> Created Time: 2019年09月03日 星期二 09时12分12秒
本题思路:简单分析过后就可以知道如果一点a被另一个点b匹配,那么和b匹配的点c不可能和点a匹配,因为每个结点都只能匹配四个方向,所以这个匹配的图就可以看做是一个二分图,因此对于每个结点,将能和他匹配的边存入,接着跑一波二分匹配之后我们得到的是无向图情况下的最大匹配,所以除以二就是最后的答案.
************************************************************************/ #include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; const int maxn = + ;
char str[maxn][maxn]; int n;
int linker[maxn * maxn];
bool used[maxn * maxn];
int tot, head[maxn * maxn];
int un[maxn * maxn], cnt; struct Edge {
int to, next;
} edge[maxn * maxn * + ]; void init() {
memset(head, -, sizeof head);
tot = ;
} void addedge(int u, int v) {
edge[tot] = (Edge) {v, head[u]};
head[u] = tot ++;
} bool dfs(int u) {
for(int k = head[u]; ~k; k = edge[k].next) {
int v = edge[k].to;
if(!used[v]) {
used[v] = true;
if(linker[v] == - || dfs(linker[v])) {
linker[v] = u;
return true;
}
}
}
return false;
} int main() {
int k, Case = ;
scanf("%d", &k);
while(k --) {
init();
cnt = ;
scanf("%d", &n);
for(int i = ; i < n; i ++) {
scanf("%s", str[i]);
}
for(int i = ; i < n; i ++) {
for(int j = ; j < n; j ++) {
if(str[i][j] == '#') {
un[cnt ++] = (i * n + j + );
for(int dx = -; dx <= ; dx ++) {
for(int dy = -; dy <= ; dy ++) {
if(abs(dx - dy) == ) {
if(dx + i >= && dx + i < n && dy + j >= && dy + j < n) {
if(str[dx + i][dy + j] == '#') addedge(i * n + j + , (i + dx) * n + j + dy + );
}
}
}
}
}
}
}
int res = ;
memset(linker, -, sizeof linker);
for(int i = ; i < cnt; i ++) {
memset(used, false, sizeof used);
if(dfs(un[i])) res ++;
}
printf("Case %d: %d\n", ++Case, res / );
}
return ;
  }

hdu-4185.loiol_skimming(简单二分匹配模型)的更多相关文章

  1. hdu 1281 棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. hdu 1853 Cyclic Tour (二分匹配KM最小权值 或 最小费用最大流)

    Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total ...

  3. hdu 1045 Fire Net(二分匹配 or 暴搜)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. POJ2239简单二分匹配

    题意:       一周有7天,每天可以上12节课,现在给你每科课的上课时间,问你一周最多可以上几科课,一科课只要上一节就行了. 思路:       简单题目,直接二分就行了,好久没写二分匹配了,练习 ...

  5. hdu 1281 棋盘游戏 (二分匹配)

    //是象棋里的车 符合二分匹配 # include<stdio.h> # include<algorithm> # include<string.h> using ...

  6. hdu 1151 Air Raid - 二分匹配

    Consider a town where all the streets are one-way and each street leads from one intersection to ano ...

  7. POJ2446 模板盖格子 简单二分匹配

    题意:       给你一个n*m的格子,有的格子上有坑,然后让你用1*2的东西去覆盖所有没有坑的格子,不能重叠,坑上也不能放东西覆盖,问是否能成功. 思路:        简单题目,每个格子和四周的 ...

  8. The Accomodation of Students HDU - 2444(判断二分图 + 二分匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. HDU - 2819 Swap(二分匹配)

    题意:交换任意两行或两列,使主对角线全为1. 分析: 1.主对角线都为1,可知最终,第一行与第一列匹配,第二行与第二列匹配,……. 2.根据初始给定的矩阵,若Aij = 1,则说明第i行与第j列匹配, ...

随机推荐

  1. devicetree推荐教程

    https://www.cnblogs.com/aaronLinux/p/5496559.html

  2. js数值排序中冒泡算法的4种简单实现

    实现数组排序的算法很多,其中冒泡算法是比较简单的冒泡的基本原理是相邻的两个数进行比较,按照排序的条件进行互换,例如对数值从小到大排序,随着不断的互换,最大的那个值会慢慢冒泡到数组的末端基于这个原理我们 ...

  3. vue开发使用vue-particles如何兼容IE11?

    最近开发vue项目,项目有一个粒子特效使用vue-particles.项目用vue-cli构建,webpack打包完毕,丢到服务器,chrome访问完美,测试360和Edge也正常.遗憾的是,在IE1 ...

  4. Thymeleaf静态资源引入方式及公共页面代码抽取

    静态资源引入 Thymeleaf模板引擎url问题,要用如下的方式写,确保在任何情况下都能访问到 <!-- Bootstrap core CSS --> <link href=&qu ...

  5. CCF201412-2 Z字形扫描 java(100分)

    试题编号: 201412-2 试题名称: Z字形扫描 时间限制: 2.0s 内存限制: 256.0MB 问题描述: 问题描述 在图像编码的算法中,需要将一个给定的方形矩阵进行Z字形扫描(Zigzag ...

  6. nginx限制文件访问速率

    需求: 一个文件下载功能需要限制文件同时访问的并发数和当个连接的访问速率: 配置: 在http context内增加: limit_conn_zone $binary_remote_addr zone ...

  7. delphi 10.3 IOS中英文错位

    delphi 每回升级都会遇到各种问题, 在安卓和windows下正常,ios遇到排版问题. 解决办法:将附件文件放至程序目录下. 百度网盘下载附件 链接: https://pan.baidu.com ...

  8. R Seurat 单细胞处理pipline 代码

    options(stringsAsFactors = F ) rm(list = ls()) library(Seurat) library(dplyr) library(ggplot2) libra ...

  9. Leetcode 4. Median of Two Sorted Arrays(中位数+二分答案+递归)

    4. Median of Two Sorted Arrays Hard There are two sorted arrays nums1 and nums2 of size m and n resp ...

  10. input 的type类型值

    input有很多属性,我们先来说一下最原始的,也就是HTML5之前的 1)text: 定义单行的输入字段,可扎起其中输入文本 2)password:定义密码字段,会显示自符掩码 3)file: 定义输 ...