/*************************************************************************
> 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. Linux shell 批量验证端口连通性

    工作中会遇到验证到某某服务器端口是否连通,如果IP或端口多时,用shell还是很省时省力的,看下面的脚本: #!/bin/bash # #database check #set -o nounset ...

  2. 详述 DB2 分页查询及 Java 实现的示例_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 博主说:有时候,我们需要对数据库中现有的数据进行大量处理操作(例如表中的某个字段需要全部更新等),如果直接使用selec ...

  3. LeetCode--078--子集(python)

    给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3]输出:[ [3],  [1],  [2],  ...

  4. 51nod1790 输出二进制数

    题目描述 题解 过于真实 LJ卡常题 一个显然的dp: 设f[i][j]表示做完前i个,最后一段为j+1~i的方案(最小值同理) 那么f[i][j]=min(f[i-j-1][k]),其中k~j-1要 ...

  5. HRESULT: 0x80040228

    When run the arcgis engine codes in the console application, may come to the exception: HRESULT: 0x8 ...

  6. 在 Postman 中报错:Self-signed SSL certificates are being blocked 的分析与解决

    http://www.shuijingwanwq.com/2019/02/18/3171/

  7. Codeforces 878A - Short Program(位运算)

    原题链接:http://codeforces.com/problemset/problem/878/A 题意:给出n个位运算操作, 化简这些操作, 使化简后的操作次数不多于5步. 思路:我们可以对二进 ...

  8. formdata方式上传文件,支持大文件分割上传

    1.upload.html <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html"> <h ...

  9. Sonys TRC save data plolicy

    帖子地址:https://forums.unrealengine.com/showthread.php?130820-Sonys-TRC-save-data-plolicy we had severa ...

  10. 学习日记15-1布局页同时引用多个model

    @model Tuple<model1,model2>  mvc布局页同时引用多个model 使用m.Item1.xxx  m.Item2.xxx