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 那道题目一样 ...
随机推荐
- Numpy的一些操作
1.什么是Numpy 简单来说: Numpy(Numerical Python)是一个开源的Python科学计算库,用于快速处理任意维度的数组. Numpy支持常见的数组和矩阵操作.对于同样的数值计算 ...
- C#获取PLC信息 (KepServer)二
具体应用呢,不多说了,上代码,取长补短就是原创 using OPCAutomation; using System; using System.Collections.Generic; using S ...
- iNeuOS工业互联网操作系统,在线报表(Excel)开发工具
目 录 1. 概述... 2 2. 视频介绍... 2 3. 应用过程... 2 1. 概述 iNeuOS工业互联网操作系统在线报表(Excel)工具的开 ...
- redis主从复制(九)
先来简单了解下redis中提供的集群策略, 虽然redis有持久化功能能够保障redis服务器宕机也能恢复并且只有少量的数据损失,但是由于所有数据在一台服务器上,如果这台服务器出现硬盘故障,那就算是有 ...
- SAP APO-供需匹配
供需匹配包含主要功能"匹配能力"(CTM)和一个用于分配库存的附加功能. 在高级计划和优化中,SDM组件为这些应用程序提供跨工厂供应策略- 生产计划和详细计划(PP / DS) 供 ...
- SAP 实例 9 Text output
REPORT demo_show_text. CLASS demo DEFINITION. PUBLIC SECTION. CLASS-METHODS main. ENDCLASS. CLASS de ...
- sql-DDL-操作数据库与表
1. 操作数据库:CRUD oracle应该是没有操作数据库的SQL oracl创建数据库通过数据库提供的工具来新建数据库 windows版oracle新建数据库 C(Create):创建 creat ...
- IP寻址与规划
一.IP寻址和子网划分 IP地址的主机部分可被分为三种地址:网络地址.主机地址和定向广播地址. 网络地址是网络号中的第一个地址.它用来将网络内的其他所有网段唯一标识为一个网段或广播域.定向广播地址是网 ...
- ByDesign各版本区别
by zyi
- Day02 HTML语法
有两种类型的标签 双标记<标记名>内容</标记名> 单标记<标记名/> 属性: 对标签的描述--属性,由属性名和属性值组成 <标记名 属性名 = " ...