只能说构图是痛苦的。。。。。完全没思路,思路在下面。。。。
无向二分图的最小路径覆盖 = 顶点数 – 最大二分匹配数/2
http://user.qzone.qq.com/289065406/blog/1299322779
code
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define lson l,m,rt << 1
#define rson m+1,r,rt<<1|1
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("input.txt","r",stdin)
#define writef freopen("output.txt","w",stdout)
const int maxn = 502;
const int INF = 0x3fffffff;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const double pi = acos(-1.0);
const double eps= 1e-7;
using namespace std;
int N,M,V1,V2,cnt,ans;//V1,V2是二分图的两个顶点集合
int city[maxn][maxn];
bool vis[maxn];//记录一边的顶点是否搜索过
bool Graph[maxn][maxn];
int link[maxn];//记录连接这个y顶点的x点
bool dfs(int x){
FOR(i,1,V2){
if(!vis[i] && Graph[x][i]){
vis[i]=true;
if(link[i]==0 || dfs(link[i])){
link[i]=x;
return true;
}
}
}
return false;
}
void getGraph(){
FOR(i,1,N) FOR(j,1,M){
if(city[i][j]){
FF(k,4){
int nx=i+dx[k];
int ny=j+dy[k];
if(city[nx][ny]){
Graph[city[i][j]][city[nx][ny]]=true;
}
}
}
}
}
int main()
{
int cas;
SD(cas);
char ch;
while(cas--){
cnt=ans=0;
SET(city,0);SET(Graph,0);SET(link,0);
SD(N);SD(M);
FOR(i,1,N) FOR(j,1,M){
scanf(" %c",&ch);
if(ch=='*'){
city[i][j]=++cnt;//代表这个点有城市
}
}
getGraph();
V1=V2=cnt;
FOR(i,1,V1){
SET(vis,false);
if(dfs(i)) ans++;
}
PD(cnt-ans/2);LN;
}
return 0;
}
分享到:
相关推荐
北大POJ3020-Antenna Placement 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
北大POJ1159-Palindrome 解题报告+AC代码
poj分类poj分类poj分类poj分类
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
北大POJ2002-Squares 解题报告+AC代码
POJ1048,加强版的约瑟夫问题 难度中等
POJ1083的代码,POJ1083的代码,POJ1083的代码
poj 百练 题目分类 poj 百练 题目分类
poj 1001答案
POJ2968代码有用,欢迎下载,POJ代码
POJ上的一道题目,自己写的代码,因为想下载别人的, 所以就放上了。
poj 1440解题报告 poj 1440解题报告 poj 1440解题报告 poj 1440解题报告