当前位置:网站首页>【SSL集训DAY3】控制棋盘【二分图匹配】
【SSL集训DAY3】控制棋盘【二分图匹配】
2022-08-09 22:35:00 【VL——MOESR】
思路:
我们浅推一波可以发现,每个格子看成一个点,向它能走到的点连边,然后就变成了最小覆盖问题
跑个匈牙利不成问题
c o d e code code
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int dx[8] = {
1, 1, 2, 2, -1, -1, -2, -2 };
const int dy[8] = {
2, -2, 1, -1, 2, -2, 1, -1 };
int n, m, btot, wtot;
int a[25][25], color[25][25], link[5010], dian[25][25];
bool v[100010], ma[5010][5010];
bool find(int x) {
for (int i = 1; i <= wtot; i++) {
if (ma[x][i] == 1 && !v[i]) {
v[i] = 1;
int q = link[i];
link[i] = x;
if (q == 0 || find(q))
return 1;
link[i] = q;
}
}
return 0;
}
int main() {
scanf("%d%d", &n, &m);
int x, y, p = 0;
while (cin >> x >> y) {
a[x][y] = 1;
p++;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (a[i][j])
continue;
if ((i % 2 == 1 && j % 2 == 1) || (i % 2 == 0 && j % 2 == 0))
color[i][j] = 1, dian[i][j] = ++ btot;
else dian[i][j] = ++ wtot;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (!a[i][j]) {
for (int k = 0; k < 8; k++) {
int xx = i + dx[k], yy = j + dy[k];
if (xx < 1 || xx > n || yy < 1 || yy > m || a[xx][yy])
continue;
if (color[i][j] == 1)
ma[dian[i][j]][dian[xx][yy]] = 1;
else
ma[dian[xx][yy]][dian[i][j]] = 1;
}
}
int ans = 0;
for (int i = 1; i <= btot; i++) {
memset(v, 0, sizeof(v));
if(find(i)) ans ++;
}
printf("%d", btot + wtot - ans);
return 0;
}
边栏推荐
- Controller层代码这么写,简洁又优雅!
- tiup cluster start
- 一体化伺服电机在三轴钻孔机中的应用
- 2022-08-09 mysql/stonedb-慢SQL-Q16分析
- 正则表达式的实际使用
- Sqlserver restricts the ip under which accounts can access the database
- complete knapsack theory
- LiveData : Transformations.map and Transformations.switchMap usage
- Filament - Material basic graphics drawing
- 【实用工具系列】MathCAD入门安装及快速上手使用教程
猜你喜欢
随机推荐
Leetcode 530. 二叉搜索树的最小绝对差
生成NC文件时,报错“未定义机床”
Qt 之 QDateEdit 和 QTimeEdit
Click: 518. Change Exchange II
Leetcode 701. 二叉搜索树中的插入操作
【集训DAY5】快速排序【模拟】【数学】
Gumbel distribution of discrete choice model
杭电多校-Counting Stickmen-(思维+组合数+容斥)
JS基础笔记-关于对象
高手这样看现货白银走势图
What are the Shenzhen fortress machine manufacturers?Which one do you recommend?
【云原生】一文讲透Kubevela addon如何添加腾讯Crane
为什么刀具数据库无法打开?
【JZOF】77按之字形打印二叉树
领跑政务云,连续五年中国第一
安踏携手华为运动健康共同验证冠军跑鞋 创新引领中国体育
Has your phone ever been monitored?
Technology feast!Huayun Data brings six topics to OpenInfra Days China
&& 不是此版本的有效语句分隔符
Click: 377. Combined Sum Ⅳ