终于知道为啥网络流这么受欢迎了。

其实就是构个图模板一下的事儿,比较好打是吧。

然后这题网络流黑白染色(其实感觉上匈牙利更加直接好想啊,但是实际上黑白染色给人感觉就是二分图)

st连白而ed连黑,流量为1

不能同时出现的就建无限流量的边

然后sum-最小割

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int dx[]={-,-,-,,,,,-};
const int dy[]={-,,,,,-,-,-}; struct node
{
int x,y,c,next,other;
}a[];int len,last[];
void ins(int x,int y,int c)
{
int k1,k2; len++;k1=len;
a[len].x=x;a[len].y=y;a[len].c=c;
a[len].next=last[x];last[x]=len; len++;k2=len;
a[len].x=y;a[len].y=x;a[len].c=;
a[len].next=last[y];last[y]=len; a[k1].other=k2;
a[k2].other=k1;
} int st,ed,h[],list[];
bool bt_h()
{
memset(h,,sizeof(h));h[st]=;
int head=,tail=;list[]=st;
while(head!=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(a[k].c>&&h[y]==)
{
h[y]=h[x]+;
list[tail]=y;
tail++;
}
}
head++;
}
if(h[ed]==)return false;
return true;
}
int findflow(int x,int f)
{
if(x==ed)return f;
int s=;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(a[k].c>&&h[y]==h[x]+&&s<f)
{
int t=findflow(y,min(a[k].c,f-s));
s+=t;a[k].c-=t;a[a[k].other].c+=t;
}
}
if(s==)h[x]=;
return s;
} int n,color[][];
char ss[];
bool mp[][];
int point(int x,int y){return (x-)*n+y;}
int main()
{
scanf("%d",&n);
int br;
int sum=;
for(int i=;i<=n;i++)
{
scanf("%s",ss+);
for(int j=;j<=n;j++)
{
if(ss[j]=='')mp[i][j]=true, sum++;
else mp[i][j]=false;
}
}
//-----sc-----
memset(color,,sizeof(color));
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(j==)color[i][j]=-color[i-][j];
else color[i][j]=-color[i][j-];
//---paint_color--- //----init----- st=n*n+,ed=n*n+;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(mp[i][j]==true)
{
if(color[i][j]==)
ins(st,point(i,j),);
else
ins(point(i,j),ed,);
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(mp[i][j]==true&&color[i][j]==)
for(int t=;t<=;t++)
{
int ti=i+dx[t],tj=j+dy[t];
if(ti>&&ti<=n&&tj>&&tj<=n&&mp[ti][tj]==true)
ins(point(i,j),point(ti,tj),);
} //----composition------ int ans=;
while(bt_h()==true)
{
ans+=findflow(st,);
}
printf("%d\n",sum-ans);
return ;
}

最新文章

  1. mysql深入浅出的笔记(存储过程一)
  2. 餐厅系统app版
  3. Android Preference
  4. O2O已死?不!美团点评们迎来新风口
  5. java中文件的读取和写入
  6. 限制&lt;input&gt;输入内容 只允许数字 或者 字母
  7. crackme_zapline分析
  8. String声明为NULL和&quot;&quot;的区别
  9. Spring中的一个错误:使用Resources时报错(The annotation @Resources is disallowed for this location)
  10. Oracle的硬解析和软解析
  11. 广州Uber优步司机奖励政策(1月18日~1月24日)
  12. bzoj 1912 巡逻(树直径)
  13. 14.4.6 Configuring Thread Concurrency for InnoDB 配置Thread 并发
  14. 更改MYSQL数据库不区分大小写表名
  15. java实现验证码
  16. 2017 年终总结 &amp; 2018 年度计划
  17. 系统uid在1-499的原因
  18. php 微信登录 公众号 获取用户信息 微信网页授权
  19. vue2打包时内存溢出解决方案
  20. Java编程的逻辑 (24) - 异常 (上)

热门文章

  1. MFC窗体大小变化
  2. Xamarin.Forms android实现沉浸式
  3. Python isalpha() 方法检测字符串是否只由字母组成。
  4. 编译器:gcc, clang, llvm
  5. Eureka组件、Eureka自我保护模式
  6. C++ CEF 浏览器中显示 Tooltip(标签中的 title 属性)
  7. springBoot启动及发布
  8. 转载:tomcat实现热部署的配置
  9. python爬虫28 | 你爬下的数据不分析一波可就亏了啊,使用python进行数据可视化
  10. ebay 店铺状态