题面

思路:

一开始以为和为了博多一样,两边连一样的,后来发现中间连负边的话根本不会割,即割断两块收益为负,所以WA的起飞……

正解是先黑白染色,每个点和它周围的点连边方式不同。对于黑点A,S-->A表示商业区的价值,A-->T表示工业区的价值,白点相反,对于相邻的情况,边权表示相邻的价值和,这样割断相当于选择同一用途,代价为正。

 #include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define rg register
#define ll long long
using namespace std; inline int gi()
{
rg int r = ; rg bool b = ; rg char c = getchar();
while ((c < '' || c > '') && c != '-') c = getchar();
if (c == '-') b = ;
while (c >= '' && c <= '') { r = (r << ) + (r << ) + c - '', c = getchar(); }
if (b) return r; return -r;
} const int inf = 2e8+, N = , M = 5e5+;
int n,m,num,S,T;
int dx[]={,,-,},dy[]={-,,,},dep[N*N],f[N*N],c[N][N];
bool col[N][N];
queue <int> q;
struct Edge
{
int to,nx,cap;
}eg[M]; inline void add(int x,int y,int z)
{
eg[++num]=(Edge){y,f[x],z}, f[x]=num;
} inline void link(int x,int y,int z)
{
add(x,y,z), add(y,x,);
} inline int dfs(int o,int flow)
{
if (o == T || !flow) return flow;
rg int to,cap,fl,tmp,i;
fl=;
for (i=f[o]; i; i=eg[i].nx)
{
to=eg[i].to, cap=eg[i].cap;
if (dep[o] != dep[to]- || cap <= )
continue;
tmp=dfs(to,min(flow,cap));
if (!tmp) continue;
fl+=tmp, flow-=tmp;
eg[i].cap-=tmp, eg[i^].cap+=tmp;
if (!flow) break;
}
if (!fl) dep[o]=;
return fl;
} inline int bfs()
{
memset(dep,,sizeof(dep));
rg int o,to,cap,i;
q.push(S); dep[S]=;
while (!q.empty())
{
o=q.front(), q.pop();
for (i=f[o]; i; i=eg[i].nx)
{
to=eg[i].to, cap=eg[i].cap;
if (dep[to] || cap <= )
continue;
dep[to]=dep[o]+, q.push(to);
}
}
return dep[T];
} inline int dinic()
{
rg int flow;
flow=;
while (bfs()) flow+=dfs(S,inf);
return flow;
} int main()
{
rg int i,j,k,x,y,dis,ans;
n=gi(), m=gi();
ans=S=, T=n*m+, num=;
for (i=; i<=n; ++i)
for (j=; j<=m; ++j)
if ((i+j)&)
col[i][j]=;
for (i=; i<=n; ++i)
for (j=; j<=m; ++j)
{
dis=gi(), ans+=dis;
if (col[i][j])
link(S,(i-)*m+j,dis);
else
link((i-)*m+j,T,dis);
} for (i=; i<=n; ++i)
for (j=; j<=m; ++j)
{
dis=gi(), ans+=dis;
if (col[i][j])
link((i-)*m+j,T,dis);
else
link(S,(i-)*m+j,dis);
}
for (i=; i<=n; ++i) for (j=; j<=m; ++j) c[i][j]=gi();
for (i=; i<=n;++i)
for (j=; j<=m; ++j)
{
if (!col[i][j]) continue;
for (k=; k<; ++k)
{
x=i+dx[k], y=j+dy[k];
if (x > n || x < || y > m || y < )
continue;
add((i-)*m+j,(x-)*m+y,c[i][j]+c[x][y]);
add((x-)*m+y,(i-)*m+j,c[i][j]+c[x][y]);
ans+=c[i][j]+c[x][y];
}
}
printf("%d\n",ans-dinic());
return ;
}

bzoj2132【圈地计划】的更多相关文章

  1. bzoj2132圈地计划

    bzoj2132圈地计划 题意: 一块土地可以纵横划分为N×M块小区域.于第i行第j列的区域,建造商业区将得到Aij收益,建造工业区将得到Bij收益.而如果区域(i,j)相邻(相邻是指两个格子有公共边 ...

  2. bzoj2132: 圈地计划(无比强大的最小割)

    2132: 圈地计划 题目:传送门 简要题意: 给出一个矩阵,一共n*m个点,并给出三个收益矩阵.A矩阵表示这个点建A的可取收益,B矩阵表示这个点建B的可取收益,C矩阵表示如果相邻(有且仅有一条公共边 ...

  3. bzoj2132: 圈地计划

    要分成两坨对吧.. 所以显然最小割 但是不兹辞啊.. 最小割是最小的啊 求最大费用怎么玩啊 那咱们就把所有费用都加起来,减掉一个最小的呗 但是两个属于不同集合的点贡献的价值是负的啊 网络流怎么跑负的啊 ...

  4. bzoj2132: 圈地计划(最小割)

    传送门 看来以后见到矩形就要黑白染色冷静一下了…… 首先,如果它的要求时候相邻的选择相同,那么就是和这一题一样了->这里 然后考虑不同的要怎么做 那就把矩形黑白染色一下吧 然后令其中一种颜色的A ...

  5. BZOJ2132 圈地计划 【最小割】

    题目 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地.据了解, 这块土地是一块矩形的区域,可以纵横划分 ...

  6. 【BZOJ2132】圈地计划(最小割)

    [BZOJ2132]圈地计划(最小割) 题面 BZOJ 题解 对我而言,不可做!!! 所以我膜烂了ZSY大佬 他的博客写了怎么做... 这,,...太强啦!! 完全想不到黑白染色之后反着连边 然后强行 ...

  7. 【BZOJ2132】圈地计划 最小割

    [BZOJ2132]圈地计划 Description 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地. ...

  8. 【BZOJ】【2132】圈地计划

    网络流/最小割 Orz Hzwer 这类大概是最小割建模中的经典应用吧…… 黑白染色,然后反转黑色的技巧感觉很巧妙!这个转化太神奇了…… /****************************** ...

  9. [BZOJ]2132: 圈地计划 最小割

    圈地计划 Description 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地.据了解,这块土地是一 ...

  10. 【bzoj2132】圈地计划 网络流最小割

    题目描述 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地.据了解,这块土地是一块矩形的区域,可以纵横划 ...

随机推荐

  1. HDU 5054 Alice and Bob(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5054 Problem Description Bob and Alice got separated ...

  2. 转:在CentOS下编译安装GCC

    转:https://teddysun.com/432.html 在CentOS下编译安装GCC 技术  秋水逸冰  发布于: 2015-09-02  更新于: 2015-09-02  6519 次围观 ...

  3. Resolving 'Root Partition Is Filling Up' Issue on Sophos UTM Firewall

    from: https://wandersick.blogspot.com/2016/06/resolving-root-partition-is-filling-up.html This is a ...

  4. poj 2932 Coneology (扫描线)

    题意 平面上有N个两两不相交的圆,求全部最外层的,即不被其它圆包括的圆的个数并输出 思路 挑战程序竞赛P259页 代码 /* ************************************* ...

  5. centos7+ 安装Docker 17.03.2

    cnetos7 安装 docker17.03.2 升级内核 http://m.blog.csdn.net/article/details?id=52047780 注意切换内核时查看 新内核位置 awk ...

  6. android页面间传递对象

    android传递对象有两种方式: 一种是Serializable和Parcelable 对于第一种方式: import java.io.Serializable; public class Shop ...

  7. JS 省市两级联动(不带地区版本)

    基于网上找的一个版本改造,因为项目需求不需要地区只要省.市,所以做了改版,两个input上直接取出了数据 <html> <head> <script src=" ...

  8. Oracle学习(十三):闪回

    1.知识点:能够对比以下的录屏进行阅读 SQL> --1. 错误地删除了记录 SQL> --2. 错误地删除了表 SQL> --3. 查询历史记录 SQL> --4. 怎样撤销 ...

  9. XShell连接不了虚拟机

    本机安装好虚拟机和centeros; 使用xshell连接: linux Could not connect to '127.0.0.1' (port 22): Connection failed. ...

  10. 按照eslint 规范写代码 [eslint] 'flag' is assigned to itself. (no-self-assign)

    按照eslint 规范写代码 [eslint] 'flag' is assigned to itself. (no-self-assign)