当前位置:网站首页>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;
}
边栏推荐
- Some updates about a hand slider (6-18, JS reverse)
- 07_ Springboot for restful style
- 【nvm】
- Docker installation MySQL simple without pit
- [ROS play with turtle turtle]
- OpenSSL SSL_ read: Connection was reset, errno 10054
- Selection (029) - what is the output of the following code?
- 力扣解法汇总515-在每个树行中找最大值
- 文件包含漏洞问题
- 从客户端到服务器
猜你喜欢

Record the range of data that MySQL update will lock

Push markdown format information to the nailing robot

07_SpingBoot 实现 RESTful 风格

File contains vulnerability issues

Super detailed cookie addition, deletion, modification and query

伪原创智能改写api百度-收录良好

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

【nvm】
Mycms we media CMS V3.0, resource push optimization, new free template
![[JS] - [string - application] - learning notes](/img/dc/f35979b094f04c0ee13b3354c7741d.png)
[JS] - [string - application] - learning notes
随机推荐
Push markdown format information to the nailing robot
[ROS play with turtle turtle]
2022 safety officer-a certificate examination questions and answers
Force deduction solution summary 515- find the maximum value in each tree row
03_ Spingboot core profile
Financial management [2]
jar中没有主清单属性
Laravel creates a service layer
Laravel 认证模块 auth
RT-thread使用rt-kprintf
Listen to the markdown file and hot update next JS page
力扣解法汇总515-在每个树行中找最大值
Notes for laravel model
Construction equipment [6]
Selection (025) - what is the output of the following code?
Main cause of EMI - mold current
2022 simulated 100 questions and simulated examination of high-altitude installation, maintenance and demolition
对抗训练理论分析:自适应步长快速对抗训练
Gocolly manual
laravel用户授权