匈牙利T了,Dinic飞了。。。

按奇偶连

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ll long long
#define u32 unsigned int
#define u64 unsigned long long #define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#include <ctime>
#define TIME() fprintf(stderr, "\ntime: %.3fms\n", clock() * 1000.0 / CLOCKS_PER_SEC); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
//char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) #endif using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; template<typename ATP>inline ATP Max(ATP a, ATP b){
return a > b ? a : b;
}
template<typename ATP>inline ATP Min(ATP a, ATP b){
return a < b ? a : b;
}
template<typename ATP>inline ATP Abs(ATP a){
return a < 0 ? -a : a;
} const int N = 207;
const int M = 500007; int n, m;
int S, T;
struct Edge{
int nxt, pre, w;
}e[M];
int head[M], cntEdge = 1;
inline void add(int u, int v, int w){
e[++cntEdge] = (Edge) { head[u], v, w}, head[u] = cntEdge;
}
inline void Add(int u, int v, int w){
add(u, v, w);
add(v, u, 0);
} int cur[M];
int q[M], d[M];
inline bool BFS(){
int h = 0, t = 1;
R(i,S,T) d[i] = -1;
d[S] = 0, q[0] = S;
while(h != t){
int u = q[h++];
if(h > 500000) h = 0;
for(register int i = head[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(e[i].w && d[v] == -1){
d[v] = d[u] + 1;
q[t++] = e[i].pre;
if(t > 500000) t = 0;
}
}
}
return d[T] != -1;
}
inline int DFS(int u, int f){
if(u == T) return f;
int w, used = 0;
for(register int i = cur[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(d[v] == d[u] + 1){
w = DFS(v, Min(f - used, e[i].w));
e[i].w -= w, e[i ^ 1].w += w;
used += w;
if(used == f) return f;
}
}
if(!used) d[u] = -1;
return used;
}
inline int Dinic(){
int sum = 0;
while(BFS()){
R(i,S,T) cur[i] = head[i];
sum += DFS(S, 0x7fffffff);
}
return sum;
}
inline int ID(int x, int y){
return (x - 1) * m + y;
} int mark[N][N];
int dx[] = {3, 3, 1, 1, -3, -3, -1, -1}, dy[] = {1, -1, 3, -3, 1, -1, 3, -3};
int main(){
int K;
io >> n >> m >> K;
S = 0, T = n * m + 1;
R(i,1,K){
int x, y;
io >> x >> y;
mark[x][y] = true;
}
R(i,1,n){
R(j,1,m){
int id = ID(i, j);
if(i & 1){
Add(S, id, 1);
}
else{
Add(id, T, 1);
}
}
}
R(i,1,n){
R(j,1,m){
if(mark[i][j]) continue;
int id = ID(i, j);
if(i & 1){
R(k,0,7){
int fx = i + dx[k], fy = j + dy[k];
if(fx < 1 || fx > n || fy < 1 || fy > m || mark[fx][fy]) continue;
int id2 = ID(fx, fy);
Add(id, id2, 1);
}
}
}
} printf("%d", n * m - K - Dinic());
return 0;
}

Luogu P5030 长脖子鹿放置(网络流)的更多相关文章

  1. P5030 长脖子鹿放置 最小割

    $ \color{#0066ff}{ 题目描述 }$ 如图所示,西洋棋的"长脖子鹿",类似于中国象棋的马,但按照"目"字攻击,且没有中国象棋"别马腿& ...

  2. P5030 长脖子鹿放置

    题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的"长脖子鹿",类似于中国象棋的马,但按照"目"字攻击,且没 ...

  3. 洛谷 - P5030 - 长脖子鹿放置 - 二分图最大独立集

    https://www.luogu.org/problemnew/show/P5030 写的第一道黑色题,图建对了. 隐约觉得互相攻击要连边,规定从奇数行流向偶数行. 二分图最大独立集=二分图顶点总数 ...

  4. 长脖子鹿放置【洛谷P5030】二分图最大独立集变形题

    题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的“长脖子鹿”,类似于中国象棋的马,但按照“目”字攻击,且没有中国象棋“别马腿”的规则.(因为长脖子 ...

  5. 洛谷[LnOI2019]长脖子鹿省选模拟赛 简要题解

    传送门 听说比赛的时候T4T4T4标程锅了??? WTF换我时间我要写T3啊 于是在T4T4T4调半天无果的情况下260pts260pts260pts收场真的是tcltcltcl. T1 快速多项式变 ...

  6. 【洛谷比赛】[LnOI2019]长脖子鹿省选模拟赛 T1 题解

    今天是[LnOI2019]长脖子鹿省选模拟赛的时间,小编表示考的不怎么样,改了半天也只会改第一题,那也先呈上题解吧. T1:P5248 [LnOI2019SP]快速多项式变换(FPT) 一看这题就很手 ...

  7. [luogu#2019/03/10模拟赛][LnOI2019]长脖子鹿省选模拟赛赛后总结

    t1-快速多项式变换(FPT) 题解 看到这个\(f(x)=a_0+a_1x+a_2x^2+a_3x^3+ \cdots + a_nx^n\)式子,我们会想到我们学习进制转换中学到的,那么我们就只需要 ...

  8. 洛谷[LnOI2019]长脖子鹿省选模拟赛t1 -> 快速多项式变换

    快速多项式 做法:刚拿到此题有点蒙,一开始真没想出来怎么做,于是试着去自己写几个例子. 自己枚举几种情况之后就基本看出来了,其实本题中 n 就是f(m)在m进制下的位数,每项的系数就是f(m)在m进制 ...

  9. [LnOI2019]长脖子鹿省选模拟赛 东京夏日相会

    这里来一发需要开毒瘤优化,并且几率很小一遍过的模拟退火题解... 友情提醒:如果你很久很久没有过某一个点,您可以加上特判 可以像 P1337 [JSOI2004]平衡点 / 吊打XXX 那道题目一样 ...

随机推荐

  1. IDEA快捷生成循环♻️

    itar 生成array for代码块 //itar for (int i = 0; i < array.length; i++) { = array[i]; } itco 生成Collecti ...

  2. 目标检测复习之Anchor Free系列

    目标检测之Anchor Free系列 CenterNet(Object as point) 见之前的过的博客 CenterNet笔记 YOLOX 见之前目标检测复习之YOLO系列总结 YOLOX笔记 ...

  3. Random方法中的nextInt(int arg0)方法讲解

    nextInt方法会生成一个随机的在5以内的数,负载均衡随机策略底层用的就是这个方法: Random rand = new Random(); int index = rand.nextInt(5); ...

  4. 可靠的分布式KV存储产品-ETCD-初见

    目录 Paxos Raft(Understandable Distributed Consensus) 名词介绍 Leader Election Log Replication 请求完整流程 etcd ...

  5. CentOS搭建BWAPP靶场并安装docker

    为了不触碰国家安全网络红线作为技术人员我们尽可能的要在自己本机在上面创建自己的靶场: 在centos上面搭建靶场看似非常简单短短几行代码,需要注意以下几个点:(1.在docker上搭建   2.端口号 ...

  6. np.r_、np.c_、np.concatenate和np.append

    np.r_是按行连接两个矩阵,就是把两矩阵上下相加,要求列数相等,最终结果的行数为两个矩阵行数和. np.c_是按列连接两个矩阵,就是把两矩阵左右相加,要求行数相等,最终结果的列数等于两矩阵的列数和. ...

  7. 内网 Ubuntu 20.04 搭建 docusaurus 项目(或前端项目)的环境(mobaxterm、tigervnc、nfs、node)

    内网 Ubuntu 20.04 搭建 docusaurus 项目(或前端项目)的环境 背景 内网开发机是 win7,只能安装 node 14 以下,而 spug 的文档项目采用的是 Facebook ...

  8. vue大型电商项目尚品汇(后台篇)day02

    这几天更新有点小慢,逐渐开始回归状态了.尽快把这个后台做完,要开始vue3了 3.添加修改品牌 用到组件 Dialog 对话框,其中visible.sync这个配置是修改他的显示隐藏的,label-w ...

  9. TypeScript(4)接口

    介绍 TypeScript 的核心原则之一是对值所具有的结构进行类型检查.我们使用接口(Interfaces)来定义对象的类型.接口是对象的状态(属性)和行为(方法)的抽象(描述) 接口初探 声明接口 ...

  10. rosbag遍历数据出错:(unicode error) 'utf-8' codec can't decode byte 0xcd in position 31: invalid continuation byte

    主题: 前言 针对ros系统记录的bag文件,可以使用python的rosbag包,按照不同起止时间和topic进行提取. 然而,有的topic可以使用rosbag读取,但是不能遍历,存在解码错误.原 ...