Codeforces Round #194 (Div. 1) B. Chips 水题

B. Chips

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/333/problem/B

Description

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 ≤ 1000, 0 ≤ 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 Input

4 3
3 1
3 2
3 3

Sample Output

1

HINT

 

题意

在N*N的棋盘边上放置棋子,每分钟把棋子向对面移动一格,要求不能进入某些特定位置,两枚棋子在某一分钟不能位于同一格且不能交换位置.求最多放多少个棋子.

题解:

一个不能进入 的位置能废掉一行和一列.设x[i]表示第i行能不能放,y[i]表示列.对于某个i来说,如果x[i]或y[i]中有真那么这里至少能放一个.如果x与 y的值同时为真,则有希望放两个(行列各一个).此时需满足这两枚棋子不能同时出现在交叉点.显然只有当n为奇数且该交点位于棋盘正中央时这是不可避免 的.

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)  
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
/*

inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
*/
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************

int a[1001];
int b[1001];
int main()
{   
    //test;
    int n,m;
    n=read(),m=read();
    for(int i=0;i<m;i++)
    {
        int x=read(),y=read();
        a[x]=1;
        b[y]=1;
    }
    int ans=0;
    for(int i=2;i<=n-1;i++)
    {
        if(a[i]+b[i]==1)
            ans++;
        if(a[i]+b[i]==0)
        {
            ans+=2;
            if(n%2==1&&i==(n+1)/2)
                ans--;
        }
    }
    cout<<ans<<endl;
}

 

posted @ 2015-05-25 18:31  qscqesze  阅读(451)  评论(0编辑  收藏  举报