UVALive 6525
二分图最大匹配
#include<cstdio>
#include<iostream>
#include<cstring>
#define MAX 10010 using namespace std ; int n, t, n1, n2, g1[1100][1100], g2[1100][1100];
char s[110][110]; bool visit[MAX];
int match[MAX];
int head[MAX]; struct edge
{
int to,next;
}e[300005]; void addedge(int u,int v)
{
e[++t].to=v;
e[t].next=head[u];
head[u]=t;
} void init ( )
{
t = n1 = n2 = 0;
memset(head, 0, sizeof(head));
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= n; ++ j)
if(s[i][j] == '.') g1[i][j] = (s[i][j] != s[i][j-1]) ? ++ n1 : g1[i][j-1];
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= n; ++ j)
if(s[i][j] == '.') g2[i][j] = (s[i][j] != s[i-1][j]) ? ++ n2: g2[i-1][j];
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= n; ++ j)
if(s[i][j] == '.') addedge(g1[i][j], g2[i][j]);
}
bool dfs(int u)
{
int i,v;
for(i = head[u]; i != 0; i = e[i].next)
{
v = e[i].to;
if(!visit[v])
{
visit[v] = true;
if(match[v] == -1 || dfs(match[v]))
{
match[v] = u;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int i,sum=0;
memset(match,-1,sizeof(match));
for(i = 1 ; i <= n1 ; ++i)
{
memset(visit,false,sizeof(visit));
if( dfs(i) )
{
sum++;
}
}
return sum;
}
int main ( )
{
while(scanf("%d", &n) == 1)
{
for(int i = 1; i <= n; ++ i)
scanf("%s", s[i]+1);
init();
int ans = MaxMatch();
printf("%d\n", ans);
}
return 0 ;
}
UVALive 6525的更多相关文章
- UVALive 6525 Attacking rooks 二分匹配 经典题
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4536">点击打开链接 题意: ...
- UVaLive 6525 Attacking rooks (二分图最大匹配)
题意:给定一个 n * n的图,X是卒, . 是空位置,让你放尽量多的车,使得他们不互相攻击. 析:把每行连续的 . 看成X集体的一个点,同理也是这样,然后求一个最大匹配即可. 代码如下: #prag ...
- The 2013 South America/Brazil Regional Contest 题解
A: UVALive 6525 cid=61196#problem/A" style="color:blue; text-decoration:none">Atta ...
- BUPT2017 wintertraining(15) #3 题解
我觉得好多套路我都不会ヘ(;´Д`ヘ) 题解拖到情人节后一天才完成,还有三场没补完,真想打死自己.( ˙-˙ ) A - 温泉旅店 UESTC - 878 题意 有n张牌,两人都可以从中拿出任意 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
随机推荐
- JS获取非行间样式及兼容问题
获取非行间样式: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- eclipse中tomcat配置(待完善)
tomcat版本:apache-tomcat-6.0.29 项目结构: 一.新建server方式 二.eclipse tomcat plugin方式 tomcat plugin方式必须保证 ...
- SQL server基本操作(一)
--1.create database CREATE DATABASE MyDB GO --2.use database USE MyDB GO --3.create table CREATE T ...
- Bring up a website by wordpress
WORDPRESS WordPress is web software you can use to create a beautiful website or blog, which is both ...
- activiti搭建(二)与Spring集成
转载请注明源地址:http://www.cnblogs.com/lighten/p/5876773.html 本文主要讲解如何将Activiti和Spring框架集成,再过一段时间将会将一个基础的de ...
- 使用inotify检测linux目录内文件变化
#include <unistd.h> #include <sys/inotify.h> #include <stdio.h> #include <error ...
- Java中String类型的不可变性和驻留池
一 基本概念 可变类和不可变类(Mutable and Immutable Objects)的初步定义: 可变类:当获得这个类的一个实例引用时,可以改变这个实例的内容. 不可变类:不可变类的实例一但创 ...
- 基于BT协议的文件分发系统
基于BT协议的文件分发系统构成: 1.一个Web服务器:保存着种子文件 2.一个种子文件:保存共享文件的一些信息(文件名,文件大小 ,Tracker服务器地址,torrent为后缀) ...
- CentOS 5.8 升级php版本
一:我们都知道系统的yum源安装出来的php版本不是5.1的就是5.3 那就是说 有些程序不支持那么低的版本的呢 那我们该怎么办呢 接下来 简单的说下php的版本升级 编译升级太慢了 这里我们选择 ...
- Git命令收集【不断更新中】
git stash 可以用来保存暂时不想提交但又被修改过的文件. git stash pop 用来取出被保存在stash栈中的修改过的所有文件. git stash show 查询哪些文件被存放在了s ...