Luogu P5030 长脖子鹿放置(网络流)
匈牙利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 长脖子鹿放置(网络流)的更多相关文章
- P5030 长脖子鹿放置 最小割
$ \color{#0066ff}{ 题目描述 }$ 如图所示,西洋棋的"长脖子鹿",类似于中国象棋的马,但按照"目"字攻击,且没有中国象棋"别马腿& ...
- P5030 长脖子鹿放置
题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的"长脖子鹿",类似于中国象棋的马,但按照"目"字攻击,且没 ...
- 洛谷 - P5030 - 长脖子鹿放置 - 二分图最大独立集
https://www.luogu.org/problemnew/show/P5030 写的第一道黑色题,图建对了. 隐约觉得互相攻击要连边,规定从奇数行流向偶数行. 二分图最大独立集=二分图顶点总数 ...
- 长脖子鹿放置【洛谷P5030】二分图最大独立集变形题
题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的“长脖子鹿”,类似于中国象棋的马,但按照“目”字攻击,且没有中国象棋“别马腿”的规则.(因为长脖子 ...
- 洛谷[LnOI2019]长脖子鹿省选模拟赛 简要题解
传送门 听说比赛的时候T4T4T4标程锅了??? WTF换我时间我要写T3啊 于是在T4T4T4调半天无果的情况下260pts260pts260pts收场真的是tcltcltcl. T1 快速多项式变 ...
- 【洛谷比赛】[LnOI2019]长脖子鹿省选模拟赛 T1 题解
今天是[LnOI2019]长脖子鹿省选模拟赛的时间,小编表示考的不怎么样,改了半天也只会改第一题,那也先呈上题解吧. T1:P5248 [LnOI2019SP]快速多项式变换(FPT) 一看这题就很手 ...
- [luogu#2019/03/10模拟赛][LnOI2019]长脖子鹿省选模拟赛赛后总结
t1-快速多项式变换(FPT) 题解 看到这个\(f(x)=a_0+a_1x+a_2x^2+a_3x^3+ \cdots + a_nx^n\)式子,我们会想到我们学习进制转换中学到的,那么我们就只需要 ...
- 洛谷[LnOI2019]长脖子鹿省选模拟赛t1 -> 快速多项式变换
快速多项式 做法:刚拿到此题有点蒙,一开始真没想出来怎么做,于是试着去自己写几个例子. 自己枚举几种情况之后就基本看出来了,其实本题中 n 就是f(m)在m进制下的位数,每项的系数就是f(m)在m进制 ...
- [LnOI2019]长脖子鹿省选模拟赛 东京夏日相会
这里来一发需要开毒瘤优化,并且几率很小一遍过的模拟退火题解... 友情提醒:如果你很久很久没有过某一个点,您可以加上特判 可以像 P1337 [JSOI2004]平衡点 / 吊打XXX 那道题目一样 ...
随机推荐
- CF1682E Unordered Swaps
鸽着,我不知道为什么对? 题意: 思路: code: #include<bits/stdc++.h> using namespace std; const int N=5e5+5; int ...
- 《Unix 网络编程》11:名字和地址转换
名字和地址转换 系列文章导航:<Unix 网络编程>笔记 域名系统 简介 域名系统主要用于主机名字和 IP 地址之间的映射.主机名可以是: 简单名字,如:centos01 全限定域名(FQ ...
- Python的关键字参数与斜杠“/”
Python3.8 新增了一种语法,可以使用斜杠 / 占据一个参数的位置,表示在此之前的参数都只接受位置参数的传参形式. 例如,对以下函数声明: def func(a, b, /, c, d, *, ...
- 跨域问题和使用 cookie 的限制
前言 在我的文章 使用 cookie 的身份验证和授权 的最后,讲到了跨域问题,这篇文章就简单介绍跨域的相关知识,并说明在 net core 中怎么设置跨域. 使用的版本为 net6,并使用 Mini ...
- 【摸鱼神器】UI库秒变LowCode工具——列表篇(一)设计与实现
内容摘要: 需求分析 定义 interface 定义 json 文件 定义列表控件的 props 基于 el-table 封装,实现依赖 json 渲染 实现内置功能:选择行(单选.多选),格式化.锁 ...
- Python数据分析--Numpy常用函数介绍(6)--Numpy中与股票成交量有关的计算
成交量(volume)是投资中一个非常重要的变量,它是指在某一时段内具体的交易数,可以在分时图中绘制,包括日线图.周线图.月线图甚至是5分钟.30分钟.60分钟图中绘制. 股票市场成交量的变化反映了资 ...
- JavaScript String -> Number
五种将String类型转化为Number类型的方法: 方法一:使用一元运算符:eg:字符串'5' +'5' -> 5; 5+null -> 5(null转化为0); '5'+nul ...
- Docker安装Jenkins打包Maven项目为Docker镜像并运行【保姆级图文教学】
一.前言 Jenkins作为CI.CD的先驱者,虽然现在的风头没有Gitlab强了,但是还是老当益壮,很多中小公司还是使用比较广泛的.最近小编经历了一次Jenkins发包,感觉还不错,所以自己学习了一 ...
- 技术分享 | Appium环境安装与架构介绍
原文链接 Appium架构 Appium 设计哲学 不需要为了自动化而重新编译或修改被测应用 不应该让移动端自动化测试限定在某种语言或者某个具体的框架 不要为了移动端的自动化测试而重新造轮子 移动端自 ...
- Redis配置登录密码
更新记录 2022年6月14日 发布. 打开配置文件 vi /etc/redis/redis.conf 搜索来找到下面这行注释 #requirepass foobared 取消注释,把 foobare ...