当前位置:网站首页>372. chessboard coverage
372. chessboard coverage
2022-06-24 23:21:00 【Searching for people far away】
Given a N That's ok N A chessboard of columns , It is known that some grids are forbidden to place .
Find the maximum number of pieces that can be placed on the chessboard. The length is 2、 Width is 1 The dominoes of , The border of the dominoes coincides with the grid ( Dominoes occupy two squares ), And any two dominoes don't overlap .
Input format
The first line contains two integers N and t, among t Is the number of cells that cannot be placed .
Next t Each line contains two integers x and y, It means to be in the second place x Xing di y Columns are not allowed to be placed in the grid , The number of rows and columns ranges from 1 Start .
Output format
Output an integer , Show the result .
Data range
1≤N≤100,
0≤t≤100
sample input :
8 0
sample output :
32
Code :
/* Because each domino will only be matched by two consecutive squares , In the sum of rows and columns of the coordinates of the square , It must be a combination of even and odd numbers , That is, each blue square in the figure will only form a domino with the surrounding white squares , Each white square will only form a domino with the surrounding blue square , Find the maximum number of combinations , So the problem is the maximum matching problem of a bipartite graph You only need the sum of the maximum matches of all the even squares , That is to say, even numbered squares are connected to odd numbered squares with a directed edge */
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 110;
int n, m;
PII match[N][N];
bool g[N][N], st[N][N];
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
bool find(int x, int y)
{
for (int i = 0; i < 4; i++)
{
int a = x + dx[i], b = y + dy[i];
if (a < 1 || a > n || b < 1 || b > n)
continue;
if (g[a][b] || st[a][b])
continue;
PII t = match[a][b];
st[a][b] = 1;
if (t.first == 0 || find(t.first, t.second))
{
match[a][b] = {
x, y};
return true;
}
}
return false;
}
int main()
{
cin >> n >> m;
while (m--)
{
int x, y;
cin >> x >> y;
g[x][y] = true;
}
int res = 0;
// Can regard sum as odd as a boy
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if ((i + j) % 2 && !g[i][j])
{
memset(st, 0, sizeof st);
if (find(i, j))
res++;
}
cout << res << endl;
return 0;
}
边栏推荐
- 2022 safety officer-a certificate examination questions and answers
- Some updates about a hand slider (6-18, JS reverse)
- 【js】-【链表-应用】-学习笔记
- EMI的主要原因-工模电流
- Canvas to add watermark to pictures
- golang convert json string to map
- . Net 7 Preview 1 has been officially released
- Docker installation redis- simple without pit
- idea创建模块提示已存在
- Blogs personal blog project details (servlet implementation)
猜你喜欢

并发之共享模型管程

Second IPO of Huafang group: grown up in Zanthoxylum bungeanum, trapped in Zanthoxylum bungeanum

【js】-【栈、队-应用】-学习笔记

Installation and deployment of ganglia

01_ Getting started with the spingboot framework

Tech Talk 活动回顾|云原生 DevOps 的 Kubernetes 技巧

【nvm】

【js】-【数组应用】-学习笔记

Ganglia 的安装与部署

宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权
随机推荐
花房集团二次IPO:成于花椒,困于花椒
Dig deep into MySQL - resolve the clustered index / secondary index / federated index of InnoDB storage engine
[JS] - [tree] - learning notes
2022 safety officer-a certificate examination questions and answers
Daily practice (22): maximum sum of continuous subarrays
[JS] - [stack, team - application] - learning notes
【基础知识】~ 半加器 & 全加器
376. 机器任务
Laravel user authorization
对抗训练理论分析:自适应步长快速对抗训练
laravel model 注意事项
宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权
EMI的主要原因-工模电流
RT-thread使用rt-kprintf
Detailed explanation of online group chat and dating platform project (servlet implementation)
Laravel 认证模块 auth
01_ Getting started with the spingboot framework
372. 棋盘覆盖
【js】-【数组应用】-学习笔记
推送Markdown格式信息到钉钉机器人