bzoj3175: [Tjoi2013]攻击装置&&4808: 马
终于知道为啥网络流这么受欢迎了。
其实就是构个图模板一下的事儿,比较好打是吧。
然后这题网络流黑白染色(其实感觉上匈牙利更加直接好想啊,但是实际上黑白染色给人感觉就是二分图)
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 ;
}
bzoj3175: [Tjoi2013]攻击装置&&4808: 马的更多相关文章
- bzoj4808: 马 & bzoj3175: [Tjoi2013]攻击装置 (黑白染色+最小割)
bzoj4808: 马 & bzoj3175: [Tjoi2013]攻击装置 题目:传送门 简要题意: 和n皇后问题差不多,但是这里是每个棋子走日子,而且有些格子不能放棋子.求最多能放多少个棋 ...
- BZOJ3175: [Tjoi2013]攻击装置
题解: 最大点独立集...好像水过头了... 不过发现我二分图好像忘完了!!! 代码: #include<cstdio> #include<cstdlib> #include& ...
- BZOJ3175 Tjoi2013 攻击装置(二分图匹配)
传送门 Description 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照"日"字攻击其周围的 8个位置(x-1,y-2),(x-2,y ...
- BZOJ3175[Tjoi2013]攻击装置——二分图最大独立集
题目描述 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照“日”字攻击其周围的 8个位置(x-1,y-2),(x-2,y-1),(x+1,y-2),(x+2,y- ...
- BZOJ3175:[TJOI2013]攻击装置(二分图最大独立集)
Description 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照“日”字攻击其周围的 8个位置(x-1,y-2),(x-2,y-1),(x+1,y-2), ...
- 【BZOJ4808/3175】马/[Tjoi2013]攻击装置 最小割
[BZOJ4808]马 Description 众所周知,马后炮是中国象棋中很厉害的一招必杀技."马走日字".本来,如果在要去的方向有别的棋子挡住(俗称"蹩马腿" ...
- 【洛谷】4304:[TJOI2013]攻击装置【最大点独立集】【二分图】2172: [国家集训队]部落战争【二分图/网络流】【最小路径覆盖】
P4304 [TJOI2013]攻击装置 题目描述 给定一个01矩阵,其中你可以在0的位置放置攻击装置. 每一个攻击装置(x,y)都可以按照“日”字攻击其周围的8个位置(x-1,y-2),(x-2,y ...
- BZOJ 3175: [Tjoi2013]攻击装置( 匈牙利 )
黑白染成二分图, 然后不能同时选的就连边, 最大匹配数为m, t为不能放的数目, 则题目所求最大点独立集为 n*n-m-t -------------------------------------- ...
- 【BZOJ 3175】 3175: [Tjoi2013]攻击装置(二分图匹配)
3175: [Tjoi2013]攻击装置 Description 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照“日”字攻击其周围的 8个位置(x-1,y-2) ...
随机推荐
- KM算法(Kuhn-Munkres)
算法理论基础: 可行顶点标号 用l(v)表示顶点v的标号,w(uv)表示边(u,v)的权,对于赋权二分图G=(X,Y),若对每条边e=xy,均有l(x)+l(y)>=w(xy),则称这个标号为G ...
- 网站卡测试用 PageSpeed Insights
这个是google测试网页的;https://developers.google.com/speed/pagespeed/insights/ PageSpeed Insights 简介 PageSpe ...
- clock_gettime 用法
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/sta ...
- 【解题报告】洛谷 P2571 [SCOI2010]传送带
[解题报告]洛谷 P2571 [SCOI2010]传送带今天无聊,很久没有做过题目了,但是又不想做什么太难的题目,所以就用洛谷随机跳题,跳到了一道题目,感觉好像不是太难. [CSDN链接](https ...
- TestNG多线程测试-注解方式实现
用@Test(invocationCount = x,threadPoolSize = y)声明,invocationCount表示执行次数,threadPoolSize表示线程池大小. packag ...
- js之定时器操作
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- top Universities in Mechanical Engineering
- 洛谷 1091 合唱队形(NOIp2004提高组)
[题解] 分别做一遍最长上升序列和最长下降序列,再枚举峰的位置计算答案即可. #include<cstdio> #include<algorithm> #include< ...
- https://blog.csdn.net/u011495642/article/details/79958444
https://blog.csdn.net/u011495642/article/details/79958444--- 一文读懂大数据平台——写给大数据开发初学者的话! 史上最详细的Hadoop环境 ...
- Elasticsearch使用总结
原文出自:https://www.2cto.com/database/201612/580142.html ELK干货:http://www.cnblogs.com/xing901022/p/4704 ...