当前位置:网站首页>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;
}
边栏推荐
- OpenSSL SSL_read: Connection was reset, errno 10054
- Blogs personal blog project details (servlet implementation)
- 【nvm】
- 01_SpingBoot 框架入门
- . Net 7 Preview 1 has been officially released
- 2022 safety officer-b certificate examination question bank and answers
- What kind of processor architecture is ARM architecture?
- golang map clear
- Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
- 从客户端到服务器
猜你喜欢

vulnhub DC: 2

A big factory interview must ask: how to solve the problem of TCP reliable transmission? 8 pictures for you to learn in detail

Epics record reference 4 -- fields for all input records and fields for all output records

研究生宿舍大盘点!令人羡慕的研究生宿舍来了!
![[JS] - [array, stack, queue, linked list basics] - Notes](/img/c6/a1bd3b8ef6476d7d549abcb442949a.png)
[JS] - [array, stack, queue, linked list basics] - Notes

【js】-【数组、栈、队列、链表基础】-笔记

01_ Getting started with the spingboot framework
![[JS] - [string - application] - learning notes](/img/dc/f35979b094f04c0ee13b3354c7741d.png)
[JS] - [string - application] - learning notes

go Cobra命令行工具入门

RT-thread使用rt-kprintf
随机推荐
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
F29oc analysis
監聽 Markdown 文件並熱更新 Next.js 頁面
【js】-【链表-应用】-学习笔记
Online group chat and dating platform test point
SQL -convert function
Tech Talk 活动回顾|云原生 DevOps 的 Kubernetes 技巧
推送Markdown格式信息到钉钉机器人
2022 simulated 100 questions and simulated examination of high-altitude installation, maintenance and demolition
Listen to the markdown file and hot update next JS page
laravel 创建 service层
laravel学习笔记
【基础知识】~ 半加器 & 全加器
第六章 网络学习相关技巧5(超参数验证)
372. 棋盘覆盖
Notes for laravel model
07_SpingBoot 实现 RESTful 风格
Servlet
Docker installation redis- simple without pit
Dig deep into MySQL - resolve the difference between clustered and non clustered indexes