Codeforces Problem 333B

来源:互联网 发布:网络文字录入员 编辑:程序博客网 时间:2024/05/22 12:30

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.

Examples
input
3 12 2
output
0
input
3 0
output
1
input
4 33 13 23 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).


题意:有n*n的网格,其中有m个格子是禁止进入的,问最多能放几个chip

   要求:

1.chip只能放在除角落外的边界处

2.每分钟可以让每个chip移动到相邻的格子

3.chip不能移入禁止的格子内

4.两个chip不能同时在一个格子内

5.两个chip不能交换位置

6.每个chip要在n-1分钟内移到对面的边界处


思路:每个可以放chip的格子的放置情况只会影响到另外三个可以放置chip的格子,对每行的第一个格子进行判断放置情况,取最优,可以得到答案

某一行或列有禁止格子则不能放chip

判断上下两个位置能放的个数和左右两个能放的个数,取多的

这种情况时最多只能放一个


#include<iostream>#include<string.h>#include<stdio.h>#define LL long longusing namespace std;int n,m,visx[1010],visy[1010];int main(){    scanf("%d%d",&n,&m);    for(int i=0;i<m;i++){        int x,y;        scanf("%d%d",&x,&y);        visx[x] = visy[y] = 1;    }    int ans = 0;    for(int i=2;i<=n-1;i++){        int x = visx[i] + visx[n-i+1];        int y = visy[i] + visy[n-i+1];        if(i==n-i+1){            if(visx[i]==0||visy[i]==0) ans++;            continue;        }        if(x>y){            visy[i] = visy[n-i+1] = 1;            ans+=2-y;        }        else{            visx[i] = visx[n-i+1] = 1;            ans+=2-x;        }    }    printf("%d\n",ans);    return 0;}