http://www.lydsy.com/JudgeOnline/problem.php?id=4823

讨厌的形状就是四联通图

左右各连一个方块

那么破坏所有满足条件的四联通就好了

按上图方式染色之后,任意满足要求的四联通块一定可以是

黑色-->紫左-->紫右-->白色

只要破坏三个箭头中的一个即可

所以可以构建最小割模型

1、源点向黑色格连流量为格子代价的边

2、黑色格向相邻的紫色格连inf边

3、与黑色格相邻的紫色格向与白色格相邻的紫色格连 流量 为 两个紫色格较小代价 的边

4、与白色相邻的紫色格向白色格连inf边

5、白色格向汇点连流量为格子代价的边

染完之后长这样:

注意:

不要在枚举紫色格子的过程中连源点汇点的边

这样会导致连重边

比如这样黑色格子就会与源点有重边,两个紫色格子各贡献了一条边

但实际我们只能用一条边

所以可以标记哪些格子与源点、汇点有边,最后再连

(再次吐槽一次bzoj的题面~~)

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<map>
  5. #include<queue>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long LL;
  10.  
  11. #define N 100002
  12. #define M 1400001
  13.  
  14. const int inf=2e9;
  15.  
  16. map<LL,int>mp;
  17.  
  18. int n,m,k;
  19. int xi[N],yi[N],zi[N];
  20.  
  21. int front[N],nxt[M<<],to[M<<],cap[M<<],tot=;
  22. int lev[N],cur[N];
  23. int src,decc;
  24. queue<int>q;
  25.  
  26. bool uses[N],uset[N];
  27.  
  28. void read(int &x)
  29. {
  30. x=; char c=getchar();
  31. while(!isdigit(c)) c=getchar();
  32. while(isdigit(c)) { x=x*+c-''; c=getchar(); }
  33. }
  34.  
  35. LL turn(int i,int j)
  36. {
  37. return 1LL*(i-)*m+j;
  38. }
  39.  
  40. void init()
  41. {
  42. read(m); read(n); read(k);
  43. int y,x;
  44. for(int i=;i<=k;++i)
  45. {
  46. read(yi[i]); read(xi[i]); read(zi[i]);
  47. mp[turn(xi[i],yi[i])]=i;
  48. }
  49. decc=k+;
  50. }
  51.  
  52. void add(int u,int v,int val)
  53. {
  54. to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; cap[tot]=val;
  55. to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; cap[tot]=;
  56. // printf("%d %d %d\n",u,v,val);
  57. }
  58.  
  59. void Add(int x,int l,int r,int y)
  60. {
  61. if(y%== || !(y%))
  62. {
  63. uses[x]=true;
  64. add(x,l,inf);
  65. }
  66. else
  67. {
  68. uset[x]=true;
  69. add(r,x,inf);
  70. }
  71. }
  72.  
  73. void build()
  74. {
  75. int x,y;
  76. int tmp,l,r;
  77. int l1,l2,l3,r1,r2,r3;
  78. for(int i=;i<=k;++i)
  79. {
  80. x=xi[i]; y=yi[i];
  81. if(y==m) continue;
  82. if(((x&) && y%==) || (!(x&) && y%==))
  83. {
  84. tmp=mp[turn(x,y+)];
  85. if(!tmp) continue;
  86. }
  87. else continue;
  88. if(x>) l1=mp[turn(x-,y)]; else l1=;
  89. if(x<n) l2=mp[turn(x+,y)]; else l2=;
  90. if(y>) l3=mp[turn(x,y-)]; else l3=;
  91. if(!(l1||l2||l3)) continue;
  92. if(x>) r1=mp[turn(x-,y+)]; else r1=;
  93. if(x<n) r2=mp[turn(x+,y+)]; else r2=;
  94. if(y<n-) r3=mp[turn(x,y+)]; else r3=;
  95. if(!(r1||r2||r3)) continue;
  96. l=i; r=tmp;
  97. if(y%==) swap(l,r);
  98. add(l,r,min(zi[l],zi[r]));
  99. if(l1) Add(l1,l,r,yi[l1]);
  100. if(l2) Add(l2,l,r,yi[l2]);
  101. if(l3) Add(l3,l,r,yi[l3]);
  102. if(r1) Add(r1,l,r,yi[r1]);
  103. if(r2) Add(r2,l,r,yi[r2]);
  104. if(r3) Add(r3,l,r,yi[r3]);
  105. }
  106. for(int i=;i<=k;++i)
  107. if(uses[i]) add(src,i,zi[i]);
  108. for(int i=;i<=k;++i)
  109. if(uset[i]) add(i,decc,zi[i]);
  110. }
  111.  
  112. bool bfs()
  113. {
  114. while(!q.empty()) q.pop();
  115. for(int i=src;i<=decc;++i) lev[i]=-,cur[i]=front[i];
  116. lev[src]=;
  117. q.push(src);
  118. int now,t;
  119. while(!q.empty())
  120. {
  121. now=q.front();
  122. q.pop();
  123. for(int i=front[now];i;i=nxt[i])
  124. {
  125. t=to[i];
  126. if(lev[t]==- && cap[i])
  127. {
  128. lev[t]=lev[now]+;
  129. if(t==decc) return true;
  130. q.push(t);
  131. }
  132. }
  133. }
  134. return false;
  135. }
  136.  
  137. int dinic(int now,int flow)
  138. {
  139. if(now==decc) return flow;
  140. int rest=,delta,t;
  141. for(int &i=cur[now];i;i=nxt[i])
  142. {
  143. t=to[i];
  144. if(lev[t]>lev[now] && cap[i])
  145. {
  146. delta=dinic(t,min(flow-rest,cap[i]));
  147. if(delta)
  148. {
  149. cap[i]-=delta;
  150. cap[i^]+=delta;
  151. rest+=delta;
  152. if(rest==flow) break;
  153. }
  154. }
  155. }
  156. if(rest!=flow) lev[now]=-;
  157. return rest;
  158. }
  159.  
  160. void solve()
  161. {
  162. int ans=;
  163. while(bfs()) ans+=dinic(src,inf);
  164. printf("%d",ans);
  165. }
  166.  
  167. int main()
  168. {
  169. freopen("data.in","r",stdin);
  170. freopen("my.out","w",stdout);
  171. init();
  172. build();
  173. solve();
  174. }

bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块的更多相关文章

  1. bzoj4823: [Cqoi2017]老C的方块(最小割)

    4823: [Cqoi2017]老C的方块 题目:传送门 题解: 毒瘤题ORZ.... 太菜了看出来是最小割啥边都不会建...狂%大佬强强强   黑白染色?不!是四个色一起染,四层图跑最小割... 很 ...

  2. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  3. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  4. bzoj千题计划251:bzoj3672: [Noi2014]购票

    http://www.lydsy.com/JudgeOnline/problem.php?id=3672 法一:线段树维护可持久化单调队列维护凸包 斜率优化DP 设dp[i] 表示i号点到根节点的最少 ...

  5. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

  6. bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)

    https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...

  7. bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...

  8. bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...

  9. bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机

    http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...

随机推荐

  1. HTML5的placeHolder在IE9下workaround引发的Bug(按下葫芦起了瓢)

    详见StackOverFlow的:Simple jQuery form Validation: Checking for empty .val() failing in ie9 due to plac ...

  2. js获取属性

    js获取属性的方法: document.getElementById(); document.getElementsByTagname(); document.getElementsByClassna ...

  3. linux_修改文件权限chmod 、改变文件/目录所有者chown

    chmod使用事例 数字方法 chmod -R 751 [FILE] ugoa方法 chmod -R u=wrx,g=rx,o=x [FILE] 说明 chmod [OPTION] [MODE] [F ...

  4. 剑指offer:滑动窗口的最大值

    滑动窗口的最大值 题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值 ...

  5. Spring的各个jar包的作用介绍

    spring4中各个jar包的介绍: Spring AOP:Spring的面向切面编程,提供AOP(面向切面编程)的实现 Spring Aspects:Spring提供的对AspectJ框架的整合Sp ...

  6. async中await是干啥的,用不用有什么区别?

    最近在研究异步编程,用的async await task啥的,但是都这几个概念很模糊,还有不太清楚await是干啥的,task又是干啥的,用不用await有什么区别,他们三个之间的联系是什么? tas ...

  7. shell特殊变量的使用

    $0 当前脚本名$# 传递给脚本的参数个数$1 第一个参数,依次类推$*,$@ 所有参数 $?      上一条命令的执行返回结果$$ 当前shell进程ID $PPID 父进程ID 下面的shell ...

  8. BBS论坛项目

    一.表结构设计: 1.帖子: class Article(models.Model): title = models.CharField(max_length=255,unique=True) cat ...

  9. ansible系列4-关闭ssh首次连接时提示

    在ansible配置文件中找到 /etc/ansible/ansible.cfg 方法1 在配置文件中找到 了解到问题原因为,我们了解到进行ssh连接时,可以使用-o参数将StrictHostKeyC ...

  10. Code First NotMapped

    转载:http://www.cnblogs.com/libingql/p/3352058.html 不需要映射的字段,添加 NotMapped 6.非数据库字段属性 在类中,如果有一些属性不需要映射到 ...