# Codeforces Round #194 (Div. 1) / 333B Chips(贪心+代码优化)

B. Chips
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases:

• At least one of the chips at least once fell to the banned cell.
• At least once two chips were on the same cell.
• At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row).

In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 10000 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned cell. All given cells are distinct.

Consider the field rows numbered from top to bottom from 1 to n, and the columns — from left to right from 1 to n.

Output

Print a single integer — the maximum points Gerald can earn in this game.

Sample test(s)
input
3 1
2 2

output
0

input
3 0

output
1

input
4 3
3 1
3 2
3 3

output
1

Note

In the first test the answer equals zero as we can't put chips into the corner cells.

In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips.

In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).

/*92ms,0KB*/

#include<cstdio>

bool isban[2][1000];

int main()
{
int n, m, x, y, count = 0;
scanf("%d%d", &n, &m);
while (m--)
{
scanf("%d%d", &x, &y);
isban[0][x] = true;
isban[1][y] = true; ///只统计相邻的两条边就行
}
for (int i = 2; i < n; ++i)
{
if (!isban[0][i])
count++;
if (!isban[1][i])
count++;
}
///在这种情况下两个chips(芯片/小木片)重合，上面多算了一次count
if (n & 1 && !(isban[0][(n + 1) >> 1] || isban[1][(n + 1) >> 1]))
count--;
printf("%d", count);
return 0;
}


/*62ms,0KB*/

#include<cstdio>

bool isban[2][1000];

int main()
{
int n, m, x, y;
scanf("%d%d", &n, &m);
int count = (n << 1) - 4;
isban[0][1]=true;
isban[0][n]=true;
isban[1][1]=true;
isban[1][n]=true;
while (m--)
{
///只统计相邻的两条边就行
scanf("%d%d", &x, &y);
if (!isban[0][x])
{
--count;
isban[0][x] = true;
}
if (!isban[1][y])
{
--count;
isban[1][y] = true;
}
}
///在这种情况下两个chips(芯片/小木片)重合，上面多算了一次count
if (n & 1 && !(isban[0][(n + 1) >> 1] || isban[1][(n + 1) >> 1]))
--count;
printf("%d", count);
return 0;
}


• 本文已收录于以下专栏：

## 【Codeforces Round 333 (Div 2)B】【贪心 多指针】Approximating a Constant Range 给定数组 相邻元素波动为1 求差值不超1的最长序连续子序列

B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 25...

## Codeforces Round #333 (Div. 2) B. Approximating a Constant Range （dp）

B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 25...

## Codeforces Round #333 (Div. 2) B. Approximating a Constant Range

B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 25...

## Codeforces Round #333 (Div. 2) B C D

B. Approximating a Constant Range题意： 给定n个数，满足任意相邻的元素之间的差值不超过1，求最长区间使得区间内最大值和最小值的差值不超过1？ 思路： 要利用题...

## 【Codeforces Round 329 (Div 2) B】【映射 排序 贪心】Anton and Lines 查看所有直线pair在[x1,x2]范围内是否有交点

#include #include #include #include #include #include #include #include #include #include #include #...

## 贪心+链——Ant Man（Codeforces Round #366 (Div. 1) B ）

• FeBr2
• 2016年09月06日 22:02
• 164

## CodeForces 602B Approximating a Constant Range(方法很多,不想费脑子就上线段树)——Codeforces Beta Round #333 (Div. 2)

CodeForces 602B Approximating a Constant Range(方法很多,不想费脑子就上线段树)——Codeforces Beta Round #333 (Div. 2)...

## 【优化&大师级代码欣赏】Codeforces Round #137 (Div. 2) / 222B Cosmic Tables (矩阵)

B. Cosmic Tables http://codeforces.com/problemset/problem/222/B time limit per test 3 seconds m...

举报原因： 您举报文章：Codeforces Round #194 (Div. 1) / 333B Chips(贪心+代码优化) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)