2021寒假集训.2018牛客多校第二场I-car[模拟]

White Cloud has a square of n×nn×n from (1,1)(1,1) to (n,n)(n,n).

White Rabbit wants to put in several cars. Each car will start moving at the same time and move from one side of one row or one line to the other. All cars have the same speed. If two cars arrive at the same time and the same position in a grid or meet in a straight line, both cars will be damaged.

White Cloud will destroy the square mm times. In each step White Cloud will destroy one grid of the square(It will break all mm grids before cars start).Any car will break when it enters a damaged grid.

White Rabbit wants to know the maximum number of cars that can be put into to ensure that there is a way that allows all cars to perform their entire journey without damage.

(update: all cars should start at the edge of the square and go towards another side, cars which start at the corner can choose either of the two directions)

For example, in a 5×55×5 square

legal

illegal (These two cars will collide at (4,4)(4,4))

illegal (One car will go into a damaged grid)

Input

The first line of input contains two integers nn and m(n≤100000,m≤100000)m(n≤100000,m≤100000)

For the next mm lines,each line contains two integers x,y(1≤x,y≤n)x,y(1≤x,y≤n), denoting the grid which is damaged by White Cloud.

Output

Print a number,denoting the maximum number of cars White Rabbit can put into.

Example

Input

2 0

Output

4

Note

 看上去极为高深复杂的一个题目,没想到本质是一个模拟

根据n的奇偶进行推测,来推出答案的公式

在算奇数的情况是,最中间的点ans会重复减掉,所以最后要++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 101000;
#define inf 2147483678

int x[maxn],y[maxn];

int main()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    if(n%2)
    {
        ans=2*n-1;
    }
    else
    {
        ans=2*n;
    }
    while(m--)
    {
        int x1,y1;
        cin>>x1>>y1;
        x[x1]=1;
        y[y1]=1;
    }
    for(int i=1;i<=n;i++)
    {
        if(x[i])
            ans--;
        if(y[i])
            ans--;
    }
    if(n%2)
    {
        if(x[n/2+1]&&y[n/2+1])
        {
            ans++;//奇数方格中间的方格会被标记两次
        }
    }
    //int x_m=0,y_m=0;
/*有可能有重复的行,列
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        ans-=2;
        if(n%2)
        {
            if(x==(n/2+1))
                x_m++;
            if(y==(n/2+1))
                y_m++;
        }
    }
    if(x_m&&y_m)
        ans--;
 */
    cout<<ans;
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值