bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823
讨厌的形状就是四联通图
且
左右各连一个方块
那么破坏所有满足条件的四联通就好了

按上图方式染色之后,任意满足要求的四联通块一定可以是
黑色-->紫左-->紫右-->白色
只要破坏三个箭头中的一个即可
所以可以构建最小割模型
1、源点向黑色格连流量为格子代价的边
2、黑色格向相邻的紫色格连inf边
3、与黑色格相邻的紫色格向与白色格相邻的紫色格连 流量 为 两个紫色格较小代价 的边
4、与白色相邻的紫色格向白色格连inf边
5、白色格向汇点连流量为格子代价的边
染完之后长这样:

注意:
不要在枚举紫色格子的过程中连源点汇点的边
这样会导致连重边

比如这样黑色格子就会与源点有重边,两个紫色格子各贡献了一条边
但实际我们只能用一条边
所以可以标记哪些格子与源点、汇点有边,最后再连
(再次吐槽一次bzoj的题面~~)
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue> using namespace std; typedef long long LL; #define N 100002
#define M 1400001 const int inf=2e9; map<LL,int>mp; int n,m,k;
int xi[N],yi[N],zi[N]; int front[N],nxt[M<<],to[M<<],cap[M<<],tot=;
int lev[N],cur[N];
int src,decc;
queue<int>q; bool uses[N],uset[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} LL turn(int i,int j)
{
return 1LL*(i-)*m+j;
} void init()
{
read(m); read(n); read(k);
int y,x;
for(int i=;i<=k;++i)
{
read(yi[i]); read(xi[i]); read(zi[i]);
mp[turn(xi[i],yi[i])]=i;
}
decc=k+;
} void add(int u,int v,int val)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; cap[tot]=val;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; cap[tot]=;
// printf("%d %d %d\n",u,v,val);
} void Add(int x,int l,int r,int y)
{
if(y%== || !(y%))
{
uses[x]=true;
add(x,l,inf);
}
else
{
uset[x]=true;
add(r,x,inf);
}
} void build()
{
int x,y;
int tmp,l,r;
int l1,l2,l3,r1,r2,r3;
for(int i=;i<=k;++i)
{
x=xi[i]; y=yi[i];
if(y==m) continue;
if(((x&) && y%==) || (!(x&) && y%==))
{
tmp=mp[turn(x,y+)];
if(!tmp) continue;
}
else continue;
if(x>) l1=mp[turn(x-,y)]; else l1=;
if(x<n) l2=mp[turn(x+,y)]; else l2=;
if(y>) l3=mp[turn(x,y-)]; else l3=;
if(!(l1||l2||l3)) continue;
if(x>) r1=mp[turn(x-,y+)]; else r1=;
if(x<n) r2=mp[turn(x+,y+)]; else r2=;
if(y<n-) r3=mp[turn(x,y+)]; else r3=;
if(!(r1||r2||r3)) continue;
l=i; r=tmp;
if(y%==) swap(l,r);
add(l,r,min(zi[l],zi[r]));
if(l1) Add(l1,l,r,yi[l1]);
if(l2) Add(l2,l,r,yi[l2]);
if(l3) Add(l3,l,r,yi[l3]);
if(r1) Add(r1,l,r,yi[r1]);
if(r2) Add(r2,l,r,yi[r2]);
if(r3) Add(r3,l,r,yi[r3]);
}
for(int i=;i<=k;++i)
if(uses[i]) add(src,i,zi[i]);
for(int i=;i<=k;++i)
if(uset[i]) add(i,decc,zi[i]);
} bool bfs()
{
while(!q.empty()) q.pop();
for(int i=src;i<=decc;++i) lev[i]=-,cur[i]=front[i];
lev[src]=;
q.push(src);
int now,t;
while(!q.empty())
{
now=q.front();
q.pop();
for(int i=front[now];i;i=nxt[i])
{
t=to[i];
if(lev[t]==- && cap[i])
{
lev[t]=lev[now]+;
if(t==decc) return true;
q.push(t);
}
}
}
return false;
} int dinic(int now,int flow)
{
if(now==decc) return flow;
int rest=,delta,t;
for(int &i=cur[now];i;i=nxt[i])
{
t=to[i];
if(lev[t]>lev[now] && cap[i])
{
delta=dinic(t,min(flow-rest,cap[i]));
if(delta)
{
cap[i]-=delta;
cap[i^]+=delta;
rest+=delta;
if(rest==flow) break;
}
}
}
if(rest!=flow) lev[now]=-;
return rest;
} void solve()
{
int ans=;
while(bfs()) ans+=dinic(src,inf);
printf("%d",ans);
} int main()
{
freopen("data.in","r",stdin);
freopen("my.out","w",stdout);
init();
build();
solve();
}
bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块的更多相关文章
- bzoj4823: [Cqoi2017]老C的方块(最小割)
4823: [Cqoi2017]老C的方块 题目:传送门 题解: 毒瘤题ORZ.... 太菜了看出来是最小割啥边都不会建...狂%大佬强强强 黑白染色?不!是四个色一起染,四层图跑最小割... 很 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划251:bzoj3672: [Noi2014]购票
http://www.lydsy.com/JudgeOnline/problem.php?id=3672 法一:线段树维护可持久化单调队列维护凸包 斜率优化DP 设dp[i] 表示i号点到根节点的最少 ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
随机推荐
- Notepad++ 大小写转换
code_field_text 普通文本 code_field_user_id 用户ID code_field_customer_id 客户ID code_field_dict 数据字典 code_f ...
- 快速简化Android截屏工作
1.安装Notepad++v6.9 2.插件管理器里Plugin Manager安装AndroidLogger 3.AndroidLogger里的capture功能抓取Android的当前屏幕截图到w ...
- 面向对象基础及UML建模语言
1.面向对象的方法起源于面向对象程序设计语言,其发展过程大体经历了初始阶段.发展阶段和成熟阶段. 2.面向对象方法主要优点 (1)从认识论的角度可以看出,面向对象方法改变了开发软件的方式. (2)面向 ...
- BZOJ1895Pku3580 supermemo——非旋转treap
题目描述 给出一个初始序列fA1;A2;:::Ang,要求你编写程序支持如下操作: 1. ADDxyD:给子序列fAx:::Ayg的每个元素都加上D.例如对f1,2, 3,4,5g执行"AD ...
- BZOJ1901Zju2112 Dynamic Rankings——树状数组套主席树
题目描述 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1 ],a[i+2]……a[j]中第k小的数是多少(1≤k ...
- BZOJ4652 NOI2016循环之美(莫比乌斯反演+杜教筛)
因为要求数值不同,不妨设gcd(x,y)=1.由提示可以知道,x/y是纯循环小数的充要条件是x·klen=x(mod y).因为x和y互质,两边同除x,得klen=1(mod y).那么当且仅当k和y ...
- python成长之路五-文件操作
1,文件操作 f = open("D:\种子.txt",encoding="utf-8",mode="r") # 打开一个种子.txt文件, ...
- MT【239】离心率最大
已知点$A$为椭圆$\dfrac{x^2}{a^2}+\dfrac{y^2}{b^2}=1(a>b>0)$的左顶点,$O$为坐标原点,过椭圆的右焦点$F$作垂直于$x$轴的直线$l$.若直 ...
- LOJ #2541. 「PKUWC 2018」猎人杀(容斥 , 期望dp , NTT优化)
题意 LOJ #2541. 「PKUWC 2018」猎人杀 题解 一道及其巧妙的题 , 参考了一下这位大佬的博客 ... 令 \(\displaystyle A = \sum_{i=1}^{n} w_ ...
- 06 Zabbix分布式监控和主被动模式
06 Zabbix分布式监控和主被动模式 zabbix proxy设置 使用zabbix代理的好处 监控拥有不可靠的远程区域 当监控项目数以万计的时候使用代理分担zabbix-proxy压力 简化分布 ...