bzoj3175: [Tjoi2013]攻击装置&&4808: 马
2024-08-26 13:22:26
终于知道为啥网络流这么受欢迎了。
其实就是构个图模板一下的事儿,比较好打是吧。
然后这题网络流黑白染色(其实感觉上匈牙利更加直接好想啊,但是实际上黑白染色给人感觉就是二分图)
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 ;
}
最新文章
- mysql深入浅出的笔记(存储过程一)
- 餐厅系统app版
- Android Preference
- O2O已死?不!美团点评们迎来新风口
- java中文件的读取和写入
- 限制<;input>;输入内容 只允许数字 或者 字母
- crackme_zapline分析
- String声明为NULL和";";的区别
- Spring中的一个错误:使用Resources时报错(The annotation @Resources is disallowed for this location)
- Oracle的硬解析和软解析
- 广州Uber优步司机奖励政策(1月18日~1月24日)
- bzoj 1912 巡逻(树直径)
- 14.4.6 Configuring Thread Concurrency for InnoDB 配置Thread 并发
- 更改MYSQL数据库不区分大小写表名
- java实现验证码
- 2017 年终总结 &; 2018 年度计划
- 系统uid在1-499的原因
- php 微信登录 公众号 获取用户信息 微信网页授权
- vue2打包时内存溢出解决方案
- Java编程的逻辑 (24) - 异常 (上)
热门文章
- MFC窗体大小变化
- Xamarin.Forms android实现沉浸式
- Python isalpha() 方法检测字符串是否只由字母组成。
- 编译器:gcc, clang, llvm
- Eureka组件、Eureka自我保护模式
- C++ CEF 浏览器中显示 Tooltip(标签中的 title 属性)
- springBoot启动及发布
- 转载:tomcat实现热部署的配置
- python爬虫28 | 你爬下的数据不分析一波可就亏了啊,使用python进行数据可视化
- ebay 店铺状态