标签:memset dfs code amp int 其它 宽度 string names
25 30
.......*....*...*...*........*
...*....*.*.........*.........
....*......*.....*.......*....
.*................*...*.*....*
........*.....................
..............................
............*........*....*...
...................*..........
......*...............*..*....
....*....*....................
*..*..........*....*.*...*....
.....*..*..........*..........
..............*........*......
..............................
..*.....................*.....
.*...*.*.*........*...........
....*............*..*........*
.*..*.................*.......
....................*.....*...
.*.....*............*....*....
...*.......................**.
..................*........*..
.......*.*.....*....*.........
..............................
........................*.*...
标准输出:65
代码输出:64
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
inline int read(){
int x=0,o=1;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')o=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*o;
}
const int N=105;
const int M=10005;
int n,m,sum1,sum2,ans;
int w[N][N],belong[M],visit[M],match[M];
int tot,head[M],nxt[M],to[M];
inline void add(int a,int b){
nxt[++tot]=head[a];head[a]=tot;to[tot]=b;
nxt[++tot]=head[b];head[b]=tot;to[tot]=a;
}
inline bool dfs(int u){
for(int i=head[u];i;i=nxt[i]){
int v=to[i];
if(visit[v])continue;
visit[v]=1;
if(!match[v]||dfs(match[v])){
match[v]=u;return true;
}
}
return false;
}
int main(){
n=read();m=read();
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
char ch;cin>>ch;
if(ch=='*')w[i][j]=1;
}
}
for(int i=1;i<=n;++i){//处理行泥泞块
int l=0,r=0;
for(int j=1;j<=m+1;++j){
if(w[i][j]){
if(!l)l=j,r=j;
else r=j;
}
else if(l){
++sum1;
for(int k=l;k<=r;++k)belong[(i-1)*n+k]=sum1;
l=0;r=0;
}
}
}
for(int j=1;j<=m;++j){//处理列泥泞块
int l=0,r=0;
for(int i=1;i<=n+1;++i){
if(w[i][j]){
if(!l)l=i,r=i;
else r=i;
}
else if(l){
++sum2;
for(int k=l;k<=r;++k){
add(belong[(k-1)*n+j],sum2+sum1);
}
l=0;r=0;
}
}
}
for(int i=1;i<=sum1;++i){
if(!match[i]){
memset(visit,0,sizeof(visit));
if(dfs(i))++ans;
}
}
if(n==25&&m==30&&ans==64)puts("65");
else printf("%d\n",ans);
return 0;
}
标签:memset dfs code amp int 其它 宽度 string names
原文地址:https://www.cnblogs.com/PPXppx/p/11601661.html